react-arborist 1.2.0 → 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.
Files changed (118) hide show
  1. package/README.md +606 -144
  2. package/dist/components/{drop-cursor.d.ts → cursor.d.ts} +0 -0
  3. package/dist/components/default-container.d.ts +7 -0
  4. package/dist/components/default-cursor.d.ts +3 -0
  5. package/dist/components/default-drag-preview.d.ts +3 -0
  6. package/dist/components/default-node.d.ts +4 -0
  7. package/dist/components/default-row.d.ts +4 -0
  8. package/dist/components/drag-preview-container.d.ts +2 -0
  9. package/dist/components/list-inner-element.d.ts +2 -0
  10. package/dist/components/provider.d.ts +11 -0
  11. package/dist/components/row-container.d.ts +8 -0
  12. package/dist/components/tree-container.d.ts +2 -0
  13. package/dist/components/tree.d.ts +5 -4
  14. package/dist/context.d.ts +20 -2
  15. package/dist/data/create-index.d.ts +5 -0
  16. package/dist/data/create-list.d.ts +4 -0
  17. package/dist/data/create-root.d.ts +5 -0
  18. package/dist/data/simple-tree.d.ts +43 -0
  19. package/dist/dnd/compute-drop.d.ts +4 -4
  20. package/dist/dnd/drag-hook.d.ts +3 -4
  21. package/dist/dnd/drop-hook.d.ts +2 -3
  22. package/dist/hooks/use-fresh-node.d.ts +2 -0
  23. package/dist/hooks/use-simple-tree.d.ts +13 -0
  24. package/dist/hooks/use-validated-props.d.ts +3 -0
  25. package/dist/index.d.ts +8 -4
  26. package/dist/index.js +1948 -973
  27. package/dist/index.js.map +1 -1
  28. package/dist/interfaces/node-api.d.ts +67 -0
  29. package/dist/interfaces/tree-api.d.ts +113 -0
  30. package/dist/module.js +1935 -979
  31. package/dist/module.js.map +1 -1
  32. package/dist/state/dnd-slice.d.ts +20 -0
  33. package/dist/state/drag-slice.d.ts +7 -0
  34. package/dist/state/edit-slice.d.ts +8 -0
  35. package/dist/state/focus-slice.d.ts +12 -0
  36. package/dist/state/initial.d.ts +3 -0
  37. package/dist/state/open-slice.d.ts +30 -0
  38. package/dist/state/root-reducer.d.ts +13 -0
  39. package/dist/state/selection-slice.d.ts +36 -0
  40. package/dist/types/dnd.d.ts +9 -0
  41. package/dist/types/handlers.d.ts +24 -0
  42. package/dist/types/renderers.d.ts +30 -0
  43. package/dist/types/state.d.ts +2 -0
  44. package/dist/types/tree-props.d.ts +44 -0
  45. package/dist/types/utils.d.ts +21 -0
  46. package/dist/utils.d.ts +15 -6
  47. package/package.json +11 -7
  48. package/src/components/cursor.tsx +15 -0
  49. package/src/components/default-container.tsx +238 -0
  50. package/src/components/{default-drop-cursor.tsx → default-cursor.tsx} +9 -8
  51. package/src/components/{preview.tsx → default-drag-preview.tsx} +25 -41
  52. package/src/components/default-node.tsx +50 -0
  53. package/src/components/default-row.tsx +21 -0
  54. package/src/components/drag-preview-container.tsx +26 -0
  55. package/src/components/list-inner-element.tsx +22 -0
  56. package/src/components/list-outer-element.tsx +26 -15
  57. package/src/components/provider.tsx +97 -0
  58. package/src/components/row-container.tsx +82 -0
  59. package/src/components/tree-container.tsx +13 -0
  60. package/src/components/tree.tsx +16 -44
  61. package/src/context.ts +36 -0
  62. package/src/data/create-index.ts +9 -0
  63. package/src/data/create-list.ts +56 -0
  64. package/src/data/create-root.ts +54 -0
  65. package/src/data/simple-tree.ts +103 -0
  66. package/src/dnd/compute-drop.ts +16 -16
  67. package/src/dnd/drag-hook.ts +25 -19
  68. package/src/dnd/drop-hook.ts +31 -17
  69. package/src/dnd/outer-drop-hook.ts +1 -1
  70. package/src/hooks/use-fresh-node.ts +16 -0
  71. package/src/hooks/use-simple-tree.ts +55 -0
  72. package/src/hooks/use-validated-props.ts +35 -0
  73. package/src/index.ts +9 -19
  74. package/src/interfaces/node-api.ts +187 -0
  75. package/src/interfaces/tree-api.ts +557 -0
  76. package/src/state/dnd-slice.ts +36 -0
  77. package/src/state/drag-slice.ts +31 -0
  78. package/src/state/edit-slice.ts +19 -0
  79. package/src/state/focus-slice.ts +28 -0
  80. package/src/state/initial.ts +14 -0
  81. package/src/state/open-slice.ts +53 -0
  82. package/src/state/root-reducer.ts +21 -0
  83. package/src/state/selection-slice.ts +75 -0
  84. package/src/types/dnd.ts +10 -0
  85. package/src/types/handlers.ts +24 -0
  86. package/src/types/renderers.ts +34 -0
  87. package/src/types/state.ts +3 -0
  88. package/src/types/tree-props.ts +64 -0
  89. package/src/types/utils.ts +26 -0
  90. package/src/utils.ts +125 -11
  91. package/tsconfig.json +1 -1
  92. package/dist/components/default-drop-cursor.d.ts +0 -3
  93. package/dist/components/list.d.ts +0 -4
  94. package/dist/components/preview.d.ts +0 -2
  95. package/dist/components/row.d.ts +0 -8
  96. package/dist/data/enrich-tree.d.ts +0 -2
  97. package/dist/data/flatten-tree.d.ts +0 -2
  98. package/dist/provider.d.ts +0 -3
  99. package/dist/reducer.d.ts +0 -46
  100. package/dist/selection/range.d.ts +0 -13
  101. package/dist/selection/selection-hook.d.ts +0 -4
  102. package/dist/selection/selection.d.ts +0 -33
  103. package/dist/tree-api.d.ts +0 -50
  104. package/dist/types.d.ts +0 -122
  105. package/src/components/drop-cursor.tsx +0 -12
  106. package/src/components/list.tsx +0 -25
  107. package/src/components/row.tsx +0 -112
  108. package/src/context.tsx +0 -13
  109. package/src/data/enrich-tree.ts +0 -74
  110. package/src/data/flatten-tree.ts +0 -17
  111. package/src/provider.tsx +0 -41
  112. package/src/reducer.ts +0 -161
  113. package/src/selection/range.ts +0 -41
  114. package/src/selection/selection-hook.ts +0 -25
  115. package/src/selection/selection.test.ts +0 -111
  116. package/src/selection/selection.ts +0 -186
  117. package/src/tree-api.ts +0 -230
  118. package/src/types.ts +0 -148
package/dist/index.js CHANGED
@@ -1,440 +1,93 @@
1
1
  var $foSVk$reactjsxruntime = require("react/jsx-runtime");
2
2
  var $foSVk$react = require("react");
3
- var $foSVk$reactdnd = require("react-dnd");
3
+ var $foSVk$usesyncexternalstoreshim = require("use-sync-external-store/shim");
4
4
  var $foSVk$reactdndhtml5backend = require("react-dnd-html5-backend");
5
- var $foSVk$memoizeone = require("memoize-one");
6
- var $foSVk$reactdom = require("react-dom");
5
+ var $foSVk$reactdnd = require("react-dnd");
6
+ var $foSVk$redux = require("redux");
7
7
  var $foSVk$reactwindow = require("react-window");
8
8
 
9
9
  function $parcel$export(e, n, v, s) {
10
10
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
11
11
  }
12
+ function $parcel$exportWildcard(dest, source) {
13
+ Object.keys(source).forEach(function(key) {
14
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
15
+ return;
16
+ }
17
+
18
+ Object.defineProperty(dest, key, {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return source[key];
22
+ }
23
+ });
24
+ });
25
+
26
+ return dest;
27
+ }
12
28
  function $parcel$interopDefault(a) {
13
29
  return a && a.__esModule ? a.default : a;
14
30
  }
15
31
 
16
32
  $parcel$export(module.exports, "Tree", () => $641461e16d1a2941$export$7fbedc92909ed28e);
17
- $parcel$export(module.exports, "TreeApi", () => $f02bc7cefcb30793$export$e2da3477247342d1);
18
-
19
33
 
20
34
 
21
35
 
22
- function $2d914ccbe0a16edd$var$createNode(model, level, parent, children, isOpen, isDraggable, isDroppable) {
23
- return {
24
- id: model.id,
25
- level: level,
26
- parent: parent,
27
- children: children,
28
- isOpen: isOpen,
29
- isDraggable: isDraggable,
30
- isDroppable: isDroppable,
31
- model: model,
32
- rowIndex: null
33
- };
34
- }
35
- function $2d914ccbe0a16edd$var$access(obj, accessor) {
36
- if (typeof accessor === "boolean") return accessor;
37
- if (typeof accessor === "string") return obj[accessor];
38
- return accessor(obj);
39
- }
40
- function $2d914ccbe0a16edd$export$9c537176392280a0(model1, hideRoot = false, getChildren = "children", isOpen = "isOpen", disableDrag = false, disableDrop = false, openByDefault = true) {
41
- function visitSelfAndChildren(model, level, parent) {
42
- const open = $2d914ccbe0a16edd$var$access(model, isOpen);
43
- const draggable = !$2d914ccbe0a16edd$var$access(model, disableDrag);
44
- const droppable = !$2d914ccbe0a16edd$var$access(model, disableDrop);
45
- const node = $2d914ccbe0a16edd$var$createNode(model, level, parent, null, open === undefined ? openByDefault : open, draggable, droppable);
46
- const children = $2d914ccbe0a16edd$var$access(model, getChildren);
47
- if (children) node.children = children.map((child)=>visitSelfAndChildren(child, level + 1, node)
48
- );
49
- return node;
50
- }
51
- return visitSelfAndChildren(model1, hideRoot ? -1 : 0, null);
52
- }
53
-
54
-
55
36
 
56
37
 
57
38
 
58
- const $6723c76b9de38fd1$export$feef243b04ff4151 = /*#__PURE__*/ $foSVk$react.createContext(null);
59
- function $6723c76b9de38fd1$export$367b0f2231a90ba0() {
60
- const value = $foSVk$react.useContext($6723c76b9de38fd1$export$feef243b04ff4151);
39
+ const $d5cb84d44d1b8acc$export$feef243b04ff4151 = (0, $foSVk$react.createContext)(null);
40
+ function $d5cb84d44d1b8acc$export$367b0f2231a90ba0() {
41
+ const value = (0, $foSVk$react.useContext)($d5cb84d44d1b8acc$export$feef243b04ff4151);
61
42
  if (value === null) throw new Error("No Tree Api Provided");
62
43
  return value;
63
44
  }
64
-
65
-
66
- class $13a483230b6b2ece$export$9a58ef0d7ad3278c {
67
- constructor(start, end){
68
- this.start = start;
69
- this.end = end;
70
- if (this.start > this.end) throw new Error("Invalid range: start larger than end");
71
- }
72
- serialize() {
73
- return [
74
- this.start,
75
- this.end
76
- ];
77
- }
78
- contains(n) {
79
- return n >= this.start && n <= this.end;
80
- }
81
- overlaps(r) {
82
- return this.contains(r.start - 1) || this.contains(r.end + 1);
83
- }
84
- combine(r) {
85
- this.start = Math.min(r.start, this.start);
86
- this.end = Math.max(r.end, this.end);
87
- }
88
- get size() {
89
- return this.end - this.start + 1;
90
- }
91
- clone() {
92
- return new $13a483230b6b2ece$export$9a58ef0d7ad3278c(this.start, this.end);
93
- }
94
- map(fn) {
95
- let returns = [];
96
- for(let i = this.start; i <= this.end; i++)returns.push(fn(i));
97
- return returns;
98
- }
99
- isEqual(other) {
100
- return this.start === other.start && this.end === other.end;
101
- }
102
- }
103
-
104
-
105
- class $974b6ba4b06bc58f$export$52baac22726c72bf {
106
- static parse(data, items) {
107
- if (data) return new $974b6ba4b06bc58f$export$52baac22726c72bf(data.ranges, data.currentIndex, data.direction, items);
108
- else return new $974b6ba4b06bc58f$export$52baac22726c72bf();
109
- }
110
- constructor(ranges = [], currentIndex = ranges.length ? ranges.length - 1 : null, direction = "none", items = []){
111
- this.ranges = [];
112
- this.direction = "none";
113
- ranges.forEach(([s, e])=>this.addRange(s, e)
114
- );
115
- this.currentIndex = currentIndex;
116
- this.direction = direction;
117
- this.items = items;
118
- }
119
- get current() {
120
- if (this.currentIndex === null) return null;
121
- const range = this.ranges[this.currentIndex];
122
- if (!range) return null;
123
- else return range;
124
- }
125
- select(n) {
126
- if (n < 0 || n >= this.items.length) return;
127
- this.clear();
128
- this.currentIndex = this.addRange(n, n);
129
- }
130
- multiSelect(n) {
131
- if (n < 0 || n >= this.items.length) return;
132
- if (this.contains(n)) return;
133
- this.currentIndex = this.addRange(n, n);
134
- this.compact(n);
135
- }
136
- deselect(n) {
137
- if (n < 0 || n >= this.items.length) return;
138
- const r1 = this.ranges.find((r)=>r.contains(n)
139
- );
140
- if (!r1) return;
141
- else if (r1.size === 1) this.removeRange(r1);
142
- else if (r1.start === n) r1.start++;
143
- else if (r1.end === n) r1.end--;
144
- else {
145
- this.removeRange(r1);
146
- this.addRange(r1.start, n - 1);
147
- this.currentIndex = this.addRange(n + 1, r1.end);
148
- }
149
- }
150
- getSelectedItems() {
151
- return this.ranges.flatMap((range)=>range.map((index)=>this.items[index]
152
- )
153
- );
154
- }
155
- extend(n) {
156
- if (n < 0 || n >= this.items.length) return;
157
- if (this.isEmpty()) this.select(n);
158
- else {
159
- const anchor = this.getAnchor();
160
- if (anchor !== null && this.current) {
161
- const [start, end] = [
162
- n,
163
- anchor
164
- ].sort((a, b)=>a - b
165
- );
166
- this.current.start = start;
167
- this.current.end = end;
168
- this.compact(n);
169
- }
170
- }
171
- }
172
- contains(n) {
173
- if (n === null) return false;
174
- return this.ranges.some((r)=>r.contains(n)
175
- );
176
- }
177
- getRanges() {
178
- return this.ranges.map((r)=>r.serialize()
179
- );
180
- }
181
- clear() {
182
- this.ranges = [];
183
- this.currentIndex = null;
184
- this.direction = "none";
185
- }
186
- serialize() {
187
- return {
188
- ranges: this.getRanges(),
189
- currentIndex: this.currentIndex,
190
- direction: this.direction
191
- };
192
- }
193
- isEqual(other) {
194
- if (other.ranges.length !== this.ranges.length) return false;
195
- for(let i = 0; i < this.ranges.length; ++i){
196
- if (!this.ranges[i].isEqual(other.ranges[i])) return false;
197
- }
198
- return true;
199
- }
200
- addRange(start, end) {
201
- const r2 = new $13a483230b6b2ece$export$9a58ef0d7ad3278c(start, end);
202
- // Keep ranges sorted by start
203
- const index = this.ranges.findIndex((r)=>r.start >= start
204
- );
205
- if (index === -1) this.ranges.push(r2);
206
- else this.ranges.splice(index, 0, r2);
207
- return index === -1 ? this.ranges.length - 1 : index;
208
- }
209
- removeRange(r) {
210
- const index = this.ranges.indexOf(r);
211
- this.ranges.splice(index, 1);
212
- if (this.isEmpty()) this.currentIndex = null;
213
- else if (index === this.currentIndex) this.currentIndex = this.ranges.length - 1;
214
- }
215
- isEmpty() {
216
- return this.ranges.length === 0;
217
- }
218
- getAnchor() {
219
- if (!this.current) return null;
220
- return this.direction === "backward" ? this.current.end : this.current.start;
221
- }
222
- getFocus() {
223
- if (!this.current) return -1;
224
- return this.direction === "backward" ? this.current.start : this.current.end;
225
- }
226
- compact(focus) {
227
- const removals = [];
228
- const current = this.current;
229
- for (let r3 of this.ranges){
230
- if (!this.current || r3 === this.current) continue;
231
- if (this.current.overlaps(r3)) {
232
- this.current.combine(r3);
233
- removals.push(r3);
234
- }
235
- }
236
- removals.forEach((r)=>this.removeRange(r)
237
- );
238
- if (current) this.currentIndex = this.ranges.indexOf(current);
239
- if (!this.current) return;
240
- if (this.current.start < focus) this.direction = "forward";
241
- else if (this.current.end > focus) this.direction = "backward";
242
- else this.direction = "none";
243
- }
244
- }
245
-
246
-
247
- const $da0693b023d53dfe$export$f6196a6c6bb539b4 = ()=>({
248
- visibleIds: [],
249
- cursor: {
250
- type: "none"
251
- },
252
- editingId: null,
253
- selection: {
254
- data: null,
255
- ids: []
256
- }
257
- })
258
- ;
259
- const $da0693b023d53dfe$export$e324594224ef24da = {
260
- setCursorLocation: (cursor)=>({
261
- type: "SET_CURSOR_LOCATION",
262
- cursor: cursor
263
- })
264
- ,
265
- setVisibleIds: (ids, idMap // id to index
266
- )=>({
267
- type: "SET_VISIBLE_IDS",
268
- ids: ids,
269
- idMap: idMap
270
- })
271
- ,
272
- select: (index, meta, shift)=>({
273
- type: "SELECT",
274
- index: index,
275
- meta: meta,
276
- shift: shift
277
- })
278
- ,
279
- selectId: (id)=>({
280
- type: "SELECT_ID",
281
- id: id
282
- })
283
- ,
284
- edit: (id)=>({
285
- type: "EDIT",
286
- id: id
287
- })
288
- ,
289
- stepUp: (shift, ids)=>({
290
- type: "STEP_UP",
291
- shift: shift
292
- })
293
- ,
294
- stepDown: (shift, ids)=>({
295
- type: "STEP_DOWN",
296
- shift: shift
297
- })
298
- };
299
- function $da0693b023d53dfe$export$1650419e431d3ba3(state, action) {
300
- switch(action.type){
301
- case "EDIT":
302
- return {
303
- ...state,
304
- editingId: action.id
305
- };
306
- case "SET_CURSOR_LOCATION":
307
- if ($da0693b023d53dfe$var$equal(state.cursor, action.cursor)) return state;
308
- else return {
309
- ...state,
310
- cursor: action.cursor
311
- };
312
- case "SELECT":
313
- var s = $974b6ba4b06bc58f$export$52baac22726c72bf.parse(state.selection.data, state.visibleIds);
314
- if (action.index === null) s.clear();
315
- else if (action.meta) {
316
- if (s.contains(action.index)) s.deselect(action.index);
317
- else s.multiSelect(action.index);
318
- } else if (action.shift) s.extend(action.index);
319
- else s.select(action.index);
320
- return {
321
- ...state,
322
- selection: {
323
- data: s.serialize(),
324
- ids: s.getSelectedItems()
325
- }
326
- };
327
- case "SELECT_ID":
328
- return {
329
- ...state,
330
- selection: {
331
- ...state.selection,
332
- ids: [
333
- action.id
334
- ]
335
- }
336
- };
337
- case "STEP_UP":
338
- var s3 = $974b6ba4b06bc58f$export$52baac22726c72bf.parse(state.selection.data, state.visibleIds);
339
- var f = s3.getFocus();
340
- if (action.shift) s3.extend(f - 1);
341
- else s3.select(f - 1);
342
- return {
343
- ...state,
344
- selection: {
345
- data: s3.serialize(),
346
- ids: s3.getSelectedItems()
347
- }
348
- };
349
- case "STEP_DOWN":
350
- var s6 = $974b6ba4b06bc58f$export$52baac22726c72bf.parse(state.selection.data, state.visibleIds);
351
- var f2 = s6.getFocus();
352
- if (action.shift) s6.extend(f2 + 1);
353
- else s6.select(f2 + 1);
354
- return {
355
- ...state,
356
- selection: {
357
- data: s6.serialize(),
358
- ids: s6.getSelectedItems()
359
- }
360
- };
361
- case "SET_VISIBLE_IDS":
362
- // The visible ids changed
363
- var ids = state.selection.ids;
364
- // Start with a blank selection
365
- var s2 = new $974b6ba4b06bc58f$export$52baac22726c72bf([], null, "none", state.visibleIds);
366
- // Add each of the old selected ids to this new selection
367
- for (let id of ids)if (id in action.idMap) s2.multiSelect(action.idMap[id]);
368
- return {
369
- ...state,
370
- visibleIds: action.ids,
371
- selection: {
372
- ids: ids,
373
- data: s2.serialize()
374
- }
375
- };
376
- default:
377
- return state;
378
- }
379
- }
380
- function $da0693b023d53dfe$var$equal(a, b) {
381
- if (a === null || b === null) return false;
382
- return JSON.stringify(a) === JSON.stringify(b);
45
+ const $d5cb84d44d1b8acc$export$f6d467aa8b3786af = (0, $foSVk$react.createContext)(null);
46
+ function $d5cb84d44d1b8acc$export$fd23f19d5d8f3033() {
47
+ const value = (0, $foSVk$react.useContext)($d5cb84d44d1b8acc$export$f6d467aa8b3786af);
48
+ if (value === null) throw new Error("Provide a NodesContext");
49
+ return value;
383
50
  }
384
-
385
-
386
-
387
- function $c63d681a73fa226b$export$de605877a37dc399(ref, api) {
388
- $foSVk$react.useEffect(()=>{
389
- const el = ref.current;
390
- const cb = (e)=>{
391
- if (e.code === "ArrowDown") {
392
- e.preventDefault();
393
- api.selectDownwards(e.shiftKey);
394
- } else if (e.code === "ArrowUp") {
395
- e.preventDefault();
396
- api.selectUpwards(e.shiftKey);
397
- }
398
- };
399
- el?.addEventListener("keydown", cb);
400
- return ()=>{
401
- el?.removeEventListener("keydown", cb);
402
- };
403
- }, [
404
- ref,
405
- api
406
- ]);
51
+ const $d5cb84d44d1b8acc$export$2d5c5ceac203fc1e = (0, $foSVk$react.createContext)(null);
52
+ function $d5cb84d44d1b8acc$export$4930f6bf413be70e() {
53
+ const value = (0, $foSVk$react.useContext)($d5cb84d44d1b8acc$export$2d5c5ceac203fc1e);
54
+ if (value === null) throw new Error("Provide a DnDContext");
55
+ return value;
407
56
  }
408
-
409
-
410
-
411
- function $d5c6a0d3e116bf17$export$79f9fa345a841d8b(root) {
412
- const list = [];
413
- let index = 0;
414
- function collect(node) {
415
- if (node.level >= 0) {
416
- node.rowIndex = index++;
417
- list.push(node);
418
- }
419
- if (node.isOpen) node.children?.forEach(collect);
420
- }
421
- collect(root);
422
- return list;
57
+ const $d5cb84d44d1b8acc$export$d0c71bc5e3e2d897 = (0, $foSVk$react.createContext)(0);
58
+ function $d5cb84d44d1b8acc$export$83a4f9dc3b36edb8() {
59
+ (0, $foSVk$react.useContext)($d5cb84d44d1b8acc$export$d0c71bc5e3e2d897);
423
60
  }
424
61
 
425
62
 
426
-
427
-
63
+ var $5c74fef433be2b0a$exports = {};
64
+
65
+ $parcel$export($5c74fef433be2b0a$exports, "TreeApi", () => $5c74fef433be2b0a$export$e2da3477247342d1);
66
+ var $eb5355379510ac9b$exports = {};
67
+
68
+ $parcel$export($eb5355379510ac9b$exports, "bound", () => $eb5355379510ac9b$export$adf7c0fe6059d774);
69
+ $parcel$export($eb5355379510ac9b$exports, "isItem", () => $eb5355379510ac9b$export$5318634f2ee07019);
70
+ $parcel$export($eb5355379510ac9b$exports, "isClosed", () => $eb5355379510ac9b$export$4210f5ea57fbae57);
71
+ $parcel$export($eb5355379510ac9b$exports, "isDecendent", () => $eb5355379510ac9b$export$1e38f72c6c546f70);
72
+ $parcel$export($eb5355379510ac9b$exports, "indexOf", () => $eb5355379510ac9b$export$305f7d4e9d4624f2);
73
+ $parcel$export($eb5355379510ac9b$exports, "noop", () => $eb5355379510ac9b$export$8793edee2d425525);
74
+ $parcel$export($eb5355379510ac9b$exports, "dfs", () => $eb5355379510ac9b$export$51b654aff22fc5a6);
75
+ $parcel$export($eb5355379510ac9b$exports, "focusNextElement", () => $eb5355379510ac9b$export$3b0237e8566c8d65);
76
+ $parcel$export($eb5355379510ac9b$exports, "focusPrevElement", () => $eb5355379510ac9b$export$33b47db07a82b2fb);
77
+ $parcel$export($eb5355379510ac9b$exports, "access", () => $eb5355379510ac9b$export$9bb0e144ba4929ca);
78
+ $parcel$export($eb5355379510ac9b$exports, "identifyNull", () => $eb5355379510ac9b$export$611823266272db76);
79
+ $parcel$export($eb5355379510ac9b$exports, "identify", () => $eb5355379510ac9b$export$65e5b62a4c490288);
80
+ $parcel$export($eb5355379510ac9b$exports, "mergeRefs", () => $eb5355379510ac9b$export$c9058316764c140e);
81
+ $parcel$export($eb5355379510ac9b$exports, "safeRun", () => $eb5355379510ac9b$export$c6d63370cef03886);
82
+ $parcel$export($eb5355379510ac9b$exports, "waitFor", () => $eb5355379510ac9b$export$9bbfceb27f687c1b);
428
83
  function $eb5355379510ac9b$export$adf7c0fe6059d774(n, min, max) {
429
84
  return Math.max(Math.min(n, max), min);
430
85
  }
431
- const $eb5355379510ac9b$export$769c5e872f5f8638 = (node)=>!!node.children
432
- ;
433
86
  function $eb5355379510ac9b$export$5318634f2ee07019(node) {
434
- return node && !$eb5355379510ac9b$export$769c5e872f5f8638(node);
87
+ return node && node.isLeaf;
435
88
  }
436
89
  function $eb5355379510ac9b$export$4210f5ea57fbae57(node) {
437
- return node && $eb5355379510ac9b$export$769c5e872f5f8638(node) && !node.isOpen;
90
+ return node && node.isInternal && !node.isOpen;
438
91
  }
439
92
  const $eb5355379510ac9b$export$1e38f72c6c546f70 = (a, b)=>{
440
93
  let n = a;
@@ -445,289 +98,648 @@ const $eb5355379510ac9b$export$1e38f72c6c546f70 = (a, b)=>{
445
98
  return false;
446
99
  };
447
100
  const $eb5355379510ac9b$export$305f7d4e9d4624f2 = (node)=>{
448
- // This should probably not throw an error, but instead return null
449
101
  if (!node.parent) throw Error("Node does not have a parent");
450
- return node.parent.children.findIndex((c)=>c.id === node.id
451
- );
102
+ return node.parent.children.findIndex((c)=>c.id === node.id);
452
103
  };
453
- function $eb5355379510ac9b$export$8793edee2d425525() {
104
+ function $eb5355379510ac9b$export$8793edee2d425525() {}
105
+ function $eb5355379510ac9b$export$51b654aff22fc5a6(node, id) {
106
+ if (!node) return null;
107
+ if (node.id === id) return node;
108
+ if (node.children) for (let child of node.children){
109
+ const result = $eb5355379510ac9b$export$51b654aff22fc5a6(child, id);
110
+ if (result) return result;
111
+ }
112
+ return null;
113
+ }
114
+ function $eb5355379510ac9b$export$3b0237e8566c8d65(target) {
115
+ const elements = $eb5355379510ac9b$var$getFocusable(target);
116
+ let next;
117
+ for(let i = 0; i < elements.length; ++i){
118
+ const item = elements[i];
119
+ if (item === target) {
120
+ next = $eb5355379510ac9b$var$nextItem(elements, i);
121
+ break;
122
+ }
123
+ }
124
+ // @ts-ignore ??
125
+ next?.focus();
126
+ }
127
+ function $eb5355379510ac9b$export$33b47db07a82b2fb(target) {
128
+ const elements = $eb5355379510ac9b$var$getFocusable(target);
129
+ let next;
130
+ for(let i = 0; i < elements.length; ++i){
131
+ const item = elements[i];
132
+ if (item === target) {
133
+ next = $eb5355379510ac9b$var$prevItem(elements, i);
134
+ break;
135
+ }
136
+ }
137
+ // @ts-ignore
138
+ next?.focus();
139
+ }
140
+ function $eb5355379510ac9b$var$nextItem(list, index) {
141
+ if (index + 1 < list.length) return list[index + 1];
142
+ else return list[0];
143
+ }
144
+ function $eb5355379510ac9b$var$prevItem(list, index) {
145
+ if (index - 1 >= 0) return list[index - 1];
146
+ else return list[list.length - 1];
147
+ }
148
+ function $eb5355379510ac9b$var$getFocusable(target) {
149
+ return Array.from(document.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([disabled]), details:not([disabled]), summary:not(:disabled)')).filter((e)=>e === target || !target.contains(e));
150
+ }
151
+ function $eb5355379510ac9b$export$9bb0e144ba4929ca(obj, accessor) {
152
+ if (typeof accessor === "boolean") return accessor;
153
+ if (typeof accessor === "string") return obj[accessor];
154
+ return accessor(obj);
155
+ }
156
+ function $eb5355379510ac9b$export$611823266272db76(obj) {
157
+ if (obj === null) return null;
158
+ else return $eb5355379510ac9b$export$65e5b62a4c490288(obj);
159
+ }
160
+ function $eb5355379510ac9b$export$65e5b62a4c490288(obj) {
161
+ return typeof obj === "string" ? obj : obj.id;
162
+ }
163
+ function $eb5355379510ac9b$export$c9058316764c140e(...refs) {
164
+ return (instance)=>{
165
+ refs.forEach((ref)=>{
166
+ if (typeof ref === "function") ref(instance);
167
+ else if (ref != null) ref.current = instance;
168
+ });
169
+ };
170
+ }
171
+ function $eb5355379510ac9b$export$c6d63370cef03886(fn, ...args) {
172
+ if (fn) return fn(...args);
173
+ }
174
+ function $eb5355379510ac9b$export$9bbfceb27f687c1b(fn) {
175
+ return new Promise((resolve, reject)=>{
176
+ let tries = 0;
177
+ function check() {
178
+ tries += 1;
179
+ if (tries === 100) reject();
180
+ if (fn()) resolve();
181
+ else setTimeout(check, 10);
182
+ }
183
+ check();
184
+ });
454
185
  }
455
186
 
456
187
 
457
188
 
458
189
 
459
-
460
- const $8b3ec294daabcf73$var$placeholderStyle = {
190
+ const $c79fefb0d0a1d13b$var$placeholderStyle = {
461
191
  display: "flex",
462
- alignItems: "center"
192
+ alignItems: "center",
193
+ zIndex: 1
463
194
  };
464
- const $8b3ec294daabcf73$var$lineStyle = {
195
+ const $c79fefb0d0a1d13b$var$lineStyle = {
465
196
  flex: 1,
466
197
  height: "2px",
467
198
  background: "#4B91E2",
468
199
  borderRadius: "1px"
469
200
  };
470
- const $8b3ec294daabcf73$var$circleStyle = {
201
+ const $c79fefb0d0a1d13b$var$circleStyle = {
471
202
  width: "4px",
472
203
  height: "4px",
473
204
  boxShadow: "0 0 0 3px #4B91E2",
474
205
  borderRadius: "50%"
475
206
  };
476
- function $8b3ec294daabcf73$var$DefaultCursor({ top: top , left: left , indent: indent }) {
207
+ const $c79fefb0d0a1d13b$export$6cb3c16721363d11 = /*#__PURE__*/ (0, ($parcel$interopDefault($foSVk$react))).memo(function DefaultCursor({ top: top , left: left , indent: indent }) {
477
208
  const style = {
478
209
  position: "absolute",
479
210
  pointerEvents: "none",
480
211
  top: top - 2 + "px",
481
- left: indent + left + "px",
212
+ left: left + "px",
482
213
  right: indent + "px"
483
214
  };
484
- return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsxs("div", {
215
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsxs)("div", {
485
216
  style: {
486
- ...$8b3ec294daabcf73$var$placeholderStyle,
217
+ ...$c79fefb0d0a1d13b$var$placeholderStyle,
487
218
  ...style
488
219
  },
489
220
  children: [
490
- /*#__PURE__*/ $foSVk$reactjsxruntime.jsx("div", {
221
+ /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("div", {
491
222
  style: {
492
- ...$8b3ec294daabcf73$var$circleStyle
223
+ ...$c79fefb0d0a1d13b$var$circleStyle
493
224
  }
494
225
  }),
495
- /*#__PURE__*/ $foSVk$reactjsxruntime.jsx("div", {
226
+ /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("div", {
496
227
  style: {
497
- ...$8b3ec294daabcf73$var$lineStyle
228
+ ...$c79fefb0d0a1d13b$var$lineStyle
498
229
  }
499
230
  })
500
231
  ]
501
- }));
232
+ });
233
+ });
234
+
235
+
236
+
237
+
238
+ function $ff6862a32cc2ac81$export$f9c541e71856c524({ node: node , attrs: attrs , innerRef: innerRef , children: children }) {
239
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("div", {
240
+ ...attrs,
241
+ ref: innerRef,
242
+ onFocus: (e)=>e.stopPropagation(),
243
+ onClick: node.handleClick,
244
+ children: children
245
+ });
246
+ }
247
+
248
+
249
+
250
+
251
+ function $3240a4b0b5620968$export$909e23cbfbbd3351(props) {
252
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsxs)("div", {
253
+ ref: props.dragHandle,
254
+ style: props.style,
255
+ children: [
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
+ })
269
+ ]
270
+ });
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
+ });
502
278
  }
503
- function $8b3ec294daabcf73$export$61a6f16446012f00(props) {
504
- return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsx($8b3ec294daabcf73$var$DefaultCursor, {
505
- ...props
506
- }));
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
+ });
507
295
  }
508
296
 
509
297
 
510
- class $f02bc7cefcb30793$export$e2da3477247342d1 {
511
- constructor(dispatch, state, props, list, listEl){
512
- this.dispatch = dispatch;
513
- this.state = state;
514
- this.props = props;
515
- this.list = list;
516
- this.listEl = listEl;
517
- this.edits = new Map();
518
- }
519
- sync(other) {
520
- this.dispatch = other.dispatch;
521
- this.state = other.state;
522
- this.props = other.props;
523
- this.list = other.list;
524
- this.listEl = other.listEl;
525
- }
526
- getNode(id) {
527
- if (id in this.idToIndex) return this.visibleNodes[this.idToIndex[id]] || null;
528
- else return null;
529
- }
530
- getSelectedIds() {
531
- return this.state.selection.ids;
532
- }
533
- edit(id) {
534
- const sid = id.toString();
535
- this.resolveEdit(sid, {
536
- cancelled: true
537
- });
538
- this.scrollToId(sid);
539
- this.dispatch($da0693b023d53dfe$export$e324594224ef24da.edit(sid));
540
- return new Promise((resolve)=>this.edits.set(sid, resolve)
541
- );
542
- }
543
- submit(id, value) {
544
- const sid = id.toString();
545
- this.onEdit(sid, value);
546
- this.dispatch($da0693b023d53dfe$export$e324594224ef24da.edit(null));
547
- this.resolveEdit(sid, {
548
- cancelled: false,
549
- value: value
550
- });
298
+ function $1297c48a54b69bac$export$e1a8e267487c59d1(id) {
299
+ return {
300
+ type: "EDIT",
301
+ id: id
302
+ };
303
+ }
304
+ function $1297c48a54b69bac$export$1650419e431d3ba3(state = {
305
+ id: null
306
+ }, action) {
307
+ if (action.type === "EDIT") return {
308
+ ...state,
309
+ id: action.id
310
+ };
311
+ else return state;
312
+ }
313
+
314
+
315
+ function $61ef7f2c3c9633e7$export$d7ddd398f22d79ef(id) {
316
+ return {
317
+ type: "FOCUS",
318
+ id: id
319
+ };
320
+ }
321
+ function $61ef7f2c3c9633e7$export$6b6c976e46a06288() {
322
+ return {
323
+ type: "TREE_BLUR"
324
+ };
325
+ }
326
+ function $61ef7f2c3c9633e7$export$1650419e431d3ba3(state = {
327
+ id: null,
328
+ treeFocused: false
329
+ }, action) {
330
+ if (action.type === "FOCUS") return {
331
+ ...state,
332
+ id: action.id,
333
+ treeFocused: true
334
+ };
335
+ else if (action.type === "TREE_BLUR") return {
336
+ ...state,
337
+ treeFocused: false
338
+ };
339
+ else return state;
340
+ }
341
+
342
+
343
+ var $9b37fe5960a1a3c6$exports = {};
344
+
345
+ $parcel$export($9b37fe5960a1a3c6$exports, "NodeApi", () => $9b37fe5960a1a3c6$export$d4b903da0f522dc8);
346
+
347
+ class $9b37fe5960a1a3c6$export$d4b903da0f522dc8 {
348
+ constructor(params){
349
+ this.tree = params.tree;
350
+ this.id = params.id;
351
+ this.data = params.data;
352
+ this.level = params.level;
353
+ this.children = params.children;
354
+ this.parent = params.parent;
355
+ this.isDraggable = params.isDraggable;
356
+ this.isDroppable = params.isDroppable;
357
+ this.rowIndex = params.rowIndex;
551
358
  }
552
- reset(id) {
553
- const sid = id.toString();
554
- this.dispatch($da0693b023d53dfe$export$e324594224ef24da.edit(null));
555
- this.resolveEdit(sid, {
556
- cancelled: true
557
- });
359
+ get isRoot() {
360
+ return this.id === (0, $0d7f39915c1a8ae9$export$ec71a3379b43ae5c);
558
361
  }
559
- resolveEdit(id, value) {
560
- const resolve = this.edits.get(id.toString());
561
- if (resolve) resolve(value);
562
- this.edits.delete(id);
362
+ get isLeaf() {
363
+ return !Array.isArray(this.children);
563
364
  }
564
- select(index, meta = false, shift = false) {
565
- this.dispatch($da0693b023d53dfe$export$e324594224ef24da.select(index, meta, shift));
365
+ get isInternal() {
366
+ return !this.isLeaf;
566
367
  }
567
- selectById(id, meta = false, shift = false) {
568
- const index = this.idToIndex[id];
569
- this.select(index, meta, shift);
368
+ get isOpen() {
369
+ return this.isLeaf ? false : this.tree.isOpen(this.id);
570
370
  }
571
- selectUpwards(shiftKey) {
572
- this.dispatch($da0693b023d53dfe$export$e324594224ef24da.stepUp(shiftKey, this.visibleIds));
371
+ get isEditing() {
372
+ return this.tree.editingId === this.id;
573
373
  }
574
- selectDownwards(shiftKey) {
575
- this.dispatch($da0693b023d53dfe$export$e324594224ef24da.stepDown(shiftKey, this.visibleIds));
374
+ get isSelected() {
375
+ return this.tree.isSelected(this.id);
576
376
  }
577
- hideCursor() {
578
- this.dispatch($da0693b023d53dfe$export$e324594224ef24da.setCursorLocation({
579
- type: "none"
580
- }));
377
+ get isSelectedStart() {
378
+ return this.isSelected && !this.prev?.isSelected;
581
379
  }
582
- showCursor(cursor) {
583
- this.dispatch($da0693b023d53dfe$export$e324594224ef24da.setCursorLocation(cursor));
380
+ get isSelectedEnd() {
381
+ return this.isSelected && !this.next?.isSelected;
584
382
  }
585
- scrollToId(id) {
586
- if (!this.list) return;
587
- const index1 = this.idToIndex[id];
588
- if (index1) this.list.current?.scrollToItem(index1);
589
- else {
590
- this.openParents(id);
591
- ($parcel$interopDefault($foSVk$reactdom)).flushSync(()=>{
592
- const index = this.idToIndex[id];
593
- if (index) this.list.current?.scrollToItem(index);
594
- });
595
- }
383
+ get isFocused() {
384
+ return this.tree.isFocused(this.id);
596
385
  }
597
- open(id) {
598
- this.onToggle(id, true);
386
+ get isDragging() {
387
+ return this.tree.isDragging(this.id);
599
388
  }
600
- openParents(id) {
601
- const node = $f02bc7cefcb30793$var$dfs(this.props.root, id);
602
- let parent = node?.parent;
603
- while(parent){
604
- this.open(parent.id);
605
- parent = parent.parent;
606
- }
389
+ get willReceiveDrop() {
390
+ return this.tree.willReceiveDrop(this.id);
607
391
  }
608
- get visibleIds() {
609
- return $f02bc7cefcb30793$var$getIds(this.visibleNodes);
392
+ get state() {
393
+ return {
394
+ isEditing: this.isEditing,
395
+ isDragging: this.isDragging,
396
+ isSelected: this.isSelected,
397
+ isSelectedStart: this.isSelectedStart,
398
+ isSelectedEnd: this.isSelectedEnd,
399
+ isFocused: this.isFocused,
400
+ isOpen: this.isOpen,
401
+ willReceiveDrop: this.willReceiveDrop
402
+ };
610
403
  }
611
- get idToIndex() {
612
- return $f02bc7cefcb30793$var$createIndex(this.visibleNodes);
404
+ get childIndex() {
405
+ if (this.parent && this.parent.children) return this.parent.children.findIndex((child)=>child.id === this.id);
406
+ else return -1;
613
407
  }
614
- get visibleNodes() {
615
- return $f02bc7cefcb30793$var$createList(this.props.root);
408
+ get next() {
409
+ if (this.rowIndex === null) return null;
410
+ return this.tree.at(this.rowIndex + 1);
616
411
  }
617
- get width() {
618
- return this.props.treeProps.width || 300;
412
+ get prev() {
413
+ if (this.rowIndex === null) return null;
414
+ return this.tree.at(this.rowIndex - 1);
619
415
  }
620
- get height() {
621
- return this.props.treeProps.height || 500;
416
+ get nextSibling() {
417
+ const i = this.childIndex;
418
+ return this.parent?.children[i + 1] ?? null;
622
419
  }
623
- get indent() {
624
- return this.props.treeProps.indent || 24;
420
+ select() {
421
+ this.tree.select(this);
625
422
  }
626
- get renderer() {
627
- return this.props.treeProps.children;
423
+ deselect() {
424
+ this.tree.deselect(this);
628
425
  }
629
- get onToggle() {
630
- return this.props.treeProps.onToggle || $eb5355379510ac9b$export$8793edee2d425525;
426
+ selectMulti() {
427
+ this.tree.selectMulti(this);
631
428
  }
632
- get rowHeight() {
633
- return this.props.treeProps.rowHeight || 24;
429
+ selectContiguous() {
430
+ this.tree.selectContiguous(this);
634
431
  }
635
- get onClick() {
636
- return this.props.treeProps.onClick || $eb5355379510ac9b$export$8793edee2d425525;
432
+ activate() {
433
+ this.tree.activate(this);
637
434
  }
638
- get onContextMenu() {
639
- return this.props.treeProps.onContextMenu || $eb5355379510ac9b$export$8793edee2d425525;
435
+ focus() {
436
+ this.tree.focus(this);
640
437
  }
641
- get onMove() {
642
- return this.props.treeProps.onMove || $eb5355379510ac9b$export$8793edee2d425525;
438
+ toggle() {
439
+ this.tree.toggle(this);
643
440
  }
644
- get onEdit() {
645
- return this.props.treeProps.onEdit || $eb5355379510ac9b$export$8793edee2d425525;
441
+ open() {
442
+ this.tree.open(this);
646
443
  }
647
- get cursorParentId() {
648
- const { cursor: cursor } = this.state;
649
- switch(cursor.type){
650
- case "highlight":
651
- return cursor.id;
652
- default:
653
- return null;
654
- }
444
+ openParents() {
445
+ this.tree.openParents(this);
655
446
  }
656
- get cursorOverFolder() {
657
- return this.state.cursor.type === "highlight";
447
+ close() {
448
+ this.tree.close(this);
658
449
  }
659
- get editingId() {
660
- return this.state.editingId;
450
+ submit(value) {
451
+ this.tree.submit(this, value);
661
452
  }
662
- isSelected(index) {
663
- const selection = $974b6ba4b06bc58f$export$52baac22726c72bf.parse(this.state.selection.data, []);
664
- return selection.contains(index);
453
+ reset() {
454
+ this.tree.reset();
665
455
  }
666
- renderDropCursor(props) {
667
- const render = this.props.treeProps.dropCursor || $8b3ec294daabcf73$export$61a6f16446012f00;
668
- return render(props);
456
+ clone() {
457
+ return new $9b37fe5960a1a3c6$export$d4b903da0f522dc8({
458
+ ...this
459
+ });
669
460
  }
670
- }
671
- const $f02bc7cefcb30793$var$getIds = ($parcel$interopDefault($foSVk$memoizeone))((nodes)=>nodes.map((n)=>n.id
672
- )
673
- );
674
- const $f02bc7cefcb30793$var$createIndex = ($parcel$interopDefault($foSVk$memoizeone))((nodes)=>{
675
- return nodes.reduce((map, node, index)=>{
676
- map[node.id] = index;
677
- return map;
678
- }, {
679
- });
680
- });
681
- const $f02bc7cefcb30793$var$createList = ($parcel$interopDefault($foSVk$memoizeone))($d5c6a0d3e116bf17$export$79f9fa345a841d8b);
682
- function $f02bc7cefcb30793$var$dfs(node, id) {
683
- if (!node) return null;
684
- if (node.id === id) return node;
685
- if (node.children) for (let child of node.children){
686
- const result = $f02bc7cefcb30793$var$dfs(child, id);
687
- if (result) return result;
461
+ edit() {
462
+ return this.tree.edit(this);
688
463
  }
689
- return null;
464
+ handleClick = (e)=>{
465
+ if (e.metaKey) this.isSelected ? this.deselect() : this.selectMulti();
466
+ else if (e.shiftKey) this.selectContiguous();
467
+ else {
468
+ this.select();
469
+ this.activate();
470
+ }
471
+ };
690
472
  }
691
473
 
692
474
 
693
- function $59c6116b7d090f1c$export$6a399b2f7f12632c(props) {
694
- const [state, dispatch] = $foSVk$react.useReducer($da0693b023d53dfe$export$1650419e431d3ba3, $da0693b023d53dfe$export$f6196a6c6bb539b4());
695
- const list = $foSVk$react.useRef(null);
696
- const listEl = $foSVk$react.useRef(null);
697
- const api = $foSVk$react.useMemo(()=>new $f02bc7cefcb30793$export$e2da3477247342d1(dispatch, state, props, list, listEl)
698
- , [
699
- dispatch,
700
- state,
701
- props,
702
- list,
703
- listEl
704
- ]);
705
- /**
706
- * This ensures that the selection remains correct even
707
- * after opening and closing a folders
708
- */ $foSVk$react.useLayoutEffect(()=>{
709
- dispatch($da0693b023d53dfe$export$e324594224ef24da.setVisibleIds(api.visibleIds, api.idToIndex));
710
- }, [
711
- dispatch,
712
- api.visibleIds,
713
- api.idToIndex,
714
- props.root
715
- ]);
716
- $foSVk$react.useImperativeHandle(props.imperativeHandle, ()=>api
717
- );
718
- $c63d681a73fa226b$export$de605877a37dc399(listEl, api);
719
- return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsx($6723c76b9de38fd1$export$feef243b04ff4151.Provider, {
720
- value: api,
721
- children: props.children
722
- }));
475
+ const $0d7f39915c1a8ae9$export$ec71a3379b43ae5c = "__REACT_ARBORIST_INTERNAL_ROOT__";
476
+ function $0d7f39915c1a8ae9$export$882461b6382ed46c(tree) {
477
+ function visitSelfAndChildren(data, level, parent) {
478
+ const id = tree.accessId(data);
479
+ const node = new (0, $9b37fe5960a1a3c6$export$d4b903da0f522dc8)({
480
+ tree: tree,
481
+ data: data,
482
+ level: level,
483
+ parent: parent,
484
+ id: id,
485
+ children: null,
486
+ isDraggable: tree.isDraggable(data),
487
+ isDroppable: tree.isDroppable(data),
488
+ rowIndex: null
489
+ });
490
+ const children = tree.accessChildren(data);
491
+ if (children) node.children = children.map((child)=>visitSelfAndChildren(child, level + 1, node));
492
+ return node;
493
+ }
494
+ const root = new (0, $9b37fe5960a1a3c6$export$d4b903da0f522dc8)({
495
+ tree: tree,
496
+ id: $0d7f39915c1a8ae9$export$ec71a3379b43ae5c,
497
+ // @ts-ignore
498
+ data: {
499
+ id: $0d7f39915c1a8ae9$export$ec71a3379b43ae5c
500
+ },
501
+ level: -1,
502
+ parent: null,
503
+ children: null,
504
+ isDraggable: true,
505
+ isDroppable: true,
506
+ rowIndex: null
507
+ });
508
+ const data = tree.props.data ?? [];
509
+ root.children = data.map((child)=>{
510
+ return visitSelfAndChildren(child, 0, root);
511
+ });
512
+ return root;
513
+ }
514
+
515
+
516
+ const $d519ceb3313d9d0e$export$e324594224ef24da = {
517
+ open (id, filtered) {
518
+ return {
519
+ type: "VISIBILITY_OPEN",
520
+ id: id,
521
+ filtered: filtered
522
+ };
523
+ },
524
+ close (id, filtered) {
525
+ return {
526
+ type: "VISIBILITY_CLOSE",
527
+ id: id,
528
+ filtered: filtered
529
+ };
530
+ },
531
+ toggle (id, filtered) {
532
+ return {
533
+ type: "VISIBILITY_TOGGLE",
534
+ id: id,
535
+ filtered: filtered
536
+ };
537
+ },
538
+ clear (filtered) {
539
+ return {
540
+ type: "VISIBILITY_CLEAR",
541
+ filtered: filtered
542
+ };
543
+ }
544
+ };
545
+ /* Reducer */ function $d519ceb3313d9d0e$var$openMapReducer(state = {}, action) {
546
+ if (action.type === "VISIBILITY_OPEN") return {
547
+ ...state,
548
+ [action.id]: true
549
+ };
550
+ else if (action.type === "VISIBILITY_CLOSE") return {
551
+ ...state,
552
+ [action.id]: false
553
+ };
554
+ else if (action.type === "VISIBILITY_TOGGLE") {
555
+ const prev = state[action.id];
556
+ return {
557
+ ...state,
558
+ [action.id]: !prev
559
+ };
560
+ } else if (action.type === "VISIBILITY_CLEAR") return {};
561
+ else return state;
562
+ }
563
+ function $d519ceb3313d9d0e$export$1650419e431d3ba3(state = {
564
+ filtered: {},
565
+ unfiltered: {}
566
+ }, action) {
567
+ if (!action.type.startsWith("VISIBILITY")) return state;
568
+ if (action.filtered) return {
569
+ ...state,
570
+ filtered: $d519ceb3313d9d0e$var$openMapReducer(state.filtered, action)
571
+ };
572
+ else return {
573
+ ...state,
574
+ unfiltered: $d519ceb3313d9d0e$var$openMapReducer(state.unfiltered, action)
575
+ };
576
+ }
577
+
578
+
579
+
580
+ const $9d556ecd8e421ffe$export$d4c72bab9d6cc13a = (props)=>({
581
+ nodes: {
582
+ // Changes together
583
+ open: {
584
+ filtered: {},
585
+ unfiltered: props?.initialOpenState ?? {}
586
+ },
587
+ focus: {
588
+ id: null,
589
+ treeFocused: false
590
+ },
591
+ edit: {
592
+ id: null
593
+ },
594
+ drag: {
595
+ id: null,
596
+ idWillReceiveDrop: null
597
+ },
598
+ selection: {
599
+ ids: new Set(),
600
+ anchor: null,
601
+ mostRecent: null
602
+ }
603
+ },
604
+ dnd: {
605
+ cursor: {
606
+ type: "none"
607
+ },
608
+ dragId: null
609
+ }
610
+ });
611
+
612
+
613
+ const $58f9381615aa3d17$export$e324594224ef24da = {
614
+ clear: ()=>({
615
+ type: "SELECTION_CLEAR"
616
+ }),
617
+ only: (id)=>({
618
+ type: "SELECTION_ONLY",
619
+ id: (0, $eb5355379510ac9b$export$65e5b62a4c490288)(id)
620
+ }),
621
+ add: (id)=>({
622
+ type: "SELECTION_ADD",
623
+ ids: (Array.isArray(id) ? id : [
624
+ id
625
+ ]).map((0, $eb5355379510ac9b$export$65e5b62a4c490288))
626
+ }),
627
+ remove: (id)=>({
628
+ type: "SELECTION_REMOVE",
629
+ ids: (Array.isArray(id) ? id : [
630
+ id
631
+ ]).map((0, $eb5355379510ac9b$export$65e5b62a4c490288))
632
+ }),
633
+ set: (ids)=>({
634
+ type: "SELECTION_SET",
635
+ ids: ids
636
+ }),
637
+ mostRecent: (id)=>({
638
+ type: "SELECTION_MOST_RECENT",
639
+ id: id === null ? null : (0, $eb5355379510ac9b$export$65e5b62a4c490288)(id)
640
+ }),
641
+ anchor: (id)=>({
642
+ type: "SELECTION_ANCHOR",
643
+ id: id === null ? null : (0, $eb5355379510ac9b$export$65e5b62a4c490288)(id)
644
+ })
645
+ };
646
+ function $58f9381615aa3d17$export$1650419e431d3ba3(state = (0, $9d556ecd8e421ffe$export$d4c72bab9d6cc13a)()["nodes"]["selection"], action) {
647
+ const ids = state.ids;
648
+ switch(action.type){
649
+ case "SELECTION_CLEAR":
650
+ return {
651
+ ...state,
652
+ ids: new Set()
653
+ };
654
+ case "SELECTION_ONLY":
655
+ return {
656
+ ...state,
657
+ ids: new Set([
658
+ action.id
659
+ ])
660
+ };
661
+ case "SELECTION_ADD":
662
+ if (action.ids.length === 0) return state;
663
+ action.ids.forEach((id)=>ids.add(id));
664
+ return {
665
+ ...state,
666
+ ids: new Set(ids)
667
+ };
668
+ case "SELECTION_REMOVE":
669
+ if (action.ids.length === 0) return state;
670
+ action.ids.forEach((id)=>ids.delete(id));
671
+ return {
672
+ ...state,
673
+ ids: new Set(ids)
674
+ };
675
+ case "SELECTION_SET":
676
+ return {
677
+ ...state,
678
+ ids: new Set(action.ids)
679
+ };
680
+ case "SELECTION_MOST_RECENT":
681
+ return {
682
+ ...state,
683
+ mostRecent: action.id
684
+ };
685
+ case "SELECTION_ANCHOR":
686
+ return {
687
+ ...state,
688
+ anchor: action.id
689
+ };
690
+ default:
691
+ return state;
692
+ }
723
693
  }
724
694
 
725
695
 
726
696
 
697
+ const $7d98f5b84ecaa66b$export$e324594224ef24da = {
698
+ cursor (cursor) {
699
+ return {
700
+ type: "DND_CURSOR",
701
+ cursor: cursor
702
+ };
703
+ },
704
+ dragStart (id) {
705
+ return {
706
+ type: "DND_DRAG_START",
707
+ id: id
708
+ };
709
+ },
710
+ dragEnd () {
711
+ return {
712
+ type: "DND_DRAG_END"
713
+ };
714
+ }
715
+ };
716
+ function $7d98f5b84ecaa66b$export$1650419e431d3ba3(state = (0, $9d556ecd8e421ffe$export$d4c72bab9d6cc13a)()["dnd"], action) {
717
+ switch(action.type){
718
+ case "DND_CURSOR":
719
+ return {
720
+ ...state,
721
+ cursor: action.cursor
722
+ };
723
+ case "DND_DRAG_START":
724
+ return {
725
+ ...state,
726
+ dragId: action.id
727
+ };
728
+ case "DND_DRAG_END":
729
+ return {
730
+ ...state,
731
+ dragId: null
732
+ };
733
+ default:
734
+ return state;
735
+ }
736
+ }
737
+
738
+
727
739
 
728
740
 
729
741
 
730
- const $8317ba945ccd0ce3$var$layerStyles = {
742
+ const $6e3db8c23c41dfc9$var$layerStyles = {
731
743
  position: "fixed",
732
744
  pointerEvents: "none",
733
745
  zIndex: 100,
@@ -736,7 +748,7 @@ const $8317ba945ccd0ce3$var$layerStyles = {
736
748
  width: "100%",
737
749
  height: "100%"
738
750
  };
739
- const $8317ba945ccd0ce3$var$getStyle = (offset)=>{
751
+ const $6e3db8c23c41dfc9$var$getStyle = (offset)=>{
740
752
  if (!offset) return {
741
753
  display: "none"
742
754
  };
@@ -745,7 +757,7 @@ const $8317ba945ccd0ce3$var$getStyle = (offset)=>{
745
757
  transform: `translate(${x}px, ${y}px)`
746
758
  };
747
759
  };
748
- const $8317ba945ccd0ce3$var$getCountStyle = (offset)=>{
760
+ const $6e3db8c23c41dfc9$var$getCountStyle = (offset)=>{
749
761
  if (!offset) return {
750
762
  display: "none"
751
763
  };
@@ -754,96 +766,195 @@ const $8317ba945ccd0ce3$var$getCountStyle = (offset)=>{
754
766
  transform: `translate(${x + 10}px, ${y + 10}px)`
755
767
  };
756
768
  };
757
- function $8317ba945ccd0ce3$export$133773870222880f() {
758
- const { offset: offset , mouse: mouse , item: item , isDragging: isDragging } = $foSVk$reactdnd.useDragLayer((m)=>({
759
- offset: m.getSourceClientOffset(),
760
- mouse: m.getClientOffset(),
761
- item: m.getItem(),
762
- isDragging: m.isDragging()
763
- })
764
- );
765
- return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsxs($8317ba945ccd0ce3$var$Overlay, {
769
+ function $6e3db8c23c41dfc9$export$84e211ad8431a387({ offset: offset , mouse: mouse , id: id , dragIds: dragIds , isDragging: isDragging }) {
770
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsxs)($6e3db8c23c41dfc9$var$Overlay, {
766
771
  isDragging: isDragging,
767
772
  children: [
768
- /*#__PURE__*/ $foSVk$reactjsxruntime.jsx($8317ba945ccd0ce3$var$Position, {
773
+ /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)($6e3db8c23c41dfc9$var$Position, {
769
774
  offset: offset,
770
- children: /*#__PURE__*/ $foSVk$reactjsxruntime.jsx($8317ba945ccd0ce3$var$PreviewNode, {
771
- item: item
775
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)($6e3db8c23c41dfc9$var$PreviewNode, {
776
+ id: id,
777
+ dragIds: dragIds
772
778
  })
773
779
  }),
774
- /*#__PURE__*/ $foSVk$reactjsxruntime.jsx($8317ba945ccd0ce3$var$Count, {
780
+ /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)($6e3db8c23c41dfc9$var$Count, {
775
781
  mouse: mouse,
776
- item: item
782
+ count: dragIds.length
777
783
  })
778
784
  ]
779
- }));
785
+ });
780
786
  }
781
- const $8317ba945ccd0ce3$var$Overlay = /*#__PURE__*/ $foSVk$react.memo(function Overlay(props) {
787
+ const $6e3db8c23c41dfc9$var$Overlay = /*#__PURE__*/ (0, $foSVk$react.memo)(function Overlay(props) {
782
788
  if (!props.isDragging) return null;
783
- return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsx("div", {
784
- style: $8317ba945ccd0ce3$var$layerStyles,
789
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("div", {
790
+ style: $6e3db8c23c41dfc9$var$layerStyles,
785
791
  children: props.children
786
- }));
792
+ });
787
793
  });
788
- function $8317ba945ccd0ce3$var$Position(props) {
789
- return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsx("div", {
794
+ function $6e3db8c23c41dfc9$var$Position(props) {
795
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("div", {
790
796
  className: "row preview",
791
- style: $8317ba945ccd0ce3$var$getStyle(props.offset),
797
+ style: $6e3db8c23c41dfc9$var$getStyle(props.offset),
792
798
  children: props.children
793
- }));
799
+ });
794
800
  }
795
- function $8317ba945ccd0ce3$var$Count(props) {
796
- const { item: item , mouse: mouse } = props;
797
- if (item?.dragIds?.length > 1) return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsx("div", {
801
+ function $6e3db8c23c41dfc9$var$Count(props) {
802
+ const { count: count , mouse: mouse } = props;
803
+ if (count > 1) return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("div", {
798
804
  className: "selected-count",
799
- style: $8317ba945ccd0ce3$var$getCountStyle(mouse),
800
- children: item.dragIds.length
801
- }));
805
+ style: $6e3db8c23c41dfc9$var$getCountStyle(mouse),
806
+ children: count
807
+ });
802
808
  else return null;
803
809
  }
804
- const $8317ba945ccd0ce3$var$PreviewNode = /*#__PURE__*/ $foSVk$react.memo(function PreviewNode(props) {
805
- const tree = $6723c76b9de38fd1$export$367b0f2231a90ba0();
806
- if (!props.item) return null;
807
- const node = tree.getNode(props.item.id);
810
+ const $6e3db8c23c41dfc9$var$PreviewNode = /*#__PURE__*/ (0, $foSVk$react.memo)(function PreviewNode(props) {
811
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
812
+ const node = tree.get(props.id);
808
813
  if (!node) return null;
809
- return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsx(tree.renderer, {
814
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)(tree.renderNode, {
810
815
  preview: true,
811
- innerRef: ()=>{
816
+ node: node,
817
+ style: {
818
+ paddingLeft: node.level * tree.indent,
819
+ opacity: 0.2,
820
+ background: "transparent"
812
821
  },
813
- data: node.model,
814
- styles: {
815
- row: {
816
- },
817
- indent: {
818
- paddingLeft: node.level * tree.indent
819
- }
822
+ tree: tree
823
+ });
824
+ });
825
+
826
+
827
+
828
+
829
+
830
+
831
+
832
+
833
+
834
+
835
+
836
+ function $e527b4e3d64e6932$export$ef961593063b03e8() {
837
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
838
+ const state = (0, $d5cb84d44d1b8acc$export$4930f6bf413be70e)();
839
+ const cursor = state.cursor;
840
+ if (!cursor || cursor.type !== "line") return null;
841
+ const indent = tree.indent;
842
+ const top = tree.rowHeight * cursor.index + ((tree.props.padding ?? tree.props.paddingTop) ?? 0);
843
+ const left = indent * cursor.level;
844
+ const Cursor = tree.renderCursor;
845
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)(Cursor, {
846
+ top: top,
847
+ left: left,
848
+ indent: indent
849
+ });
850
+ }
851
+
852
+
853
+ const $0e2adc7837d85ac3$export$70c2b8898b86d3ad = /*#__PURE__*/ (0, $foSVk$react.forwardRef)(function Outer(props, ref) {
854
+ const { children: children , ...rest } = props;
855
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
856
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsxs)("div", {
857
+ // @ts-ignore
858
+ ref: ref,
859
+ ...rest,
860
+ onClick: (e)=>{
861
+ if (e.currentTarget === e.target) tree.deselectAll();
820
862
  },
821
- tree: tree,
822
- state: {
823
- isDragging: false,
824
- isEditing: false,
825
- isSelected: false,
826
- isSelectedStart: false,
827
- isSelectedEnd: false,
828
- isHoveringOverChild: false,
829
- isOpen: node.isOpen
863
+ children: [
864
+ /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)($0e2adc7837d85ac3$var$DropContainer, {}),
865
+ children
866
+ ]
867
+ });
868
+ });
869
+ const $0e2adc7837d85ac3$var$DropContainer = ()=>{
870
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
871
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("div", {
872
+ style: {
873
+ height: tree.visibleNodes.length * tree.rowHeight,
874
+ width: "100%",
875
+ position: "absolute",
876
+ left: "0",
877
+ right: "0"
830
878
  },
831
- handlers: {
832
- edit: ()=>Promise.resolve({
833
- cancelled: true
834
- })
835
- ,
836
- select: ()=>{
837
- },
838
- toggle: ()=>{
839
- },
840
- submit: ()=>{
879
+ onClick: (e)=>{
880
+ console.log(e.currentTarget, e.target);
881
+ },
882
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $e527b4e3d64e6932$export$ef961593063b03e8), {})
883
+ });
884
+ };
885
+
886
+
887
+
888
+
889
+
890
+
891
+ const $472f3c5b35f3bf96$export$a9af0da3ae60cd00 = /*#__PURE__*/ (0, $foSVk$react.forwardRef)(function InnerElement({ style: style , ...rest }, ref) {
892
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
893
+ const paddingTop = (tree.props.padding ?? tree.props.paddingTop) ?? 0;
894
+ const paddingBottom = (tree.props.padding ?? tree.props.paddingBottom) ?? 0;
895
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("div", {
896
+ ref: ref,
897
+ style: {
898
+ ...style,
899
+ height: `${parseFloat(style.height) + paddingTop + paddingBottom}px`
900
+ },
901
+ ...rest
902
+ });
903
+ });
904
+
905
+
906
+
907
+
908
+
909
+
910
+
911
+
912
+
913
+
914
+
915
+
916
+ function $74bee24dbb0f3e2b$export$715c0d031ede7907(node) {
917
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
918
+ const ids = tree.selectedIds;
919
+ const [_, ref, preview] = (0, $foSVk$reactdnd.useDrag)(()=>({
920
+ canDrag: ()=>node.isDraggable,
921
+ type: "NODE",
922
+ item: ()=>({
923
+ id: node.id,
924
+ dragIds: tree.isSelected(node.id) ? Array.from(ids) : [
925
+ node.id
926
+ ]
927
+ }),
928
+ start: ()=>{
929
+ tree.dispatch((0, $7d98f5b84ecaa66b$export$e324594224ef24da).dragStart(node.id));
841
930
  },
842
- reset: ()=>{
931
+ end: (item, monitor)=>{
932
+ tree.dispatch((0, $7d98f5b84ecaa66b$export$e324594224ef24da).dragEnd());
933
+ tree.hideCursor();
934
+ const drop = monitor.getDropResult();
935
+ // If they held down meta, we need to create a copy
936
+ // if (drop.dropEffect === "copy")
937
+ if (drop && drop.parentId) {
938
+ (0, $eb5355379510ac9b$export$c6d63370cef03886)(tree.props.onMove, {
939
+ dragIds: item.dragIds,
940
+ parentId: drop.parentId === (0, $0d7f39915c1a8ae9$export$ec71a3379b43ae5c) ? null : drop.parentId,
941
+ index: drop.index
942
+ });
943
+ tree.open(drop.parentId);
944
+ }
843
945
  }
844
- }
845
- }));
846
- });
946
+ }), [
947
+ ids,
948
+ node
949
+ ]);
950
+ (0, $foSVk$react.useEffect)(()=>{
951
+ preview((0, $foSVk$reactdndhtml5backend.getEmptyImage)());
952
+ }, [
953
+ preview
954
+ ]);
955
+ return ref;
956
+ }
957
+
847
958
 
848
959
 
849
960
 
@@ -876,7 +987,7 @@ function $462841de7cc5b715$var$getNodesAroundCursor(node, prev, next, hover) {
876
987
  prev,
877
988
  null
878
989
  ];
879
- if ($eb5355379510ac9b$export$769c5e872f5f8638(node)) {
990
+ if (node.isInternal) {
880
991
  if (hover.atTop) return [
881
992
  prev,
882
993
  node
@@ -913,12 +1024,12 @@ function $462841de7cc5b715$var$getDropLevel(hovering, aboveCursor, belowCursor,
913
1024
  max = aboveCursor.level;
914
1025
  min = belowCursor.level;
915
1026
  }
916
- return $eb5355379510ac9b$export$adf7c0fe6059d774(hoverLevel, min, max);
1027
+ return (0, $eb5355379510ac9b$export$adf7c0fe6059d774)(hoverLevel, min, max);
917
1028
  }
918
1029
  function $462841de7cc5b715$var$canDrop(above, below) {
919
1030
  if (!above) return true;
920
1031
  let n = above;
921
- if ($eb5355379510ac9b$export$4210f5ea57fbae57(above) && above !== below) n = above.parent;
1032
+ if ((0, $eb5355379510ac9b$export$4210f5ea57fbae57)(above) && above !== below) n = above.parent;
922
1033
  while(n){
923
1034
  if (!n.isDroppable) return false;
924
1035
  n = n.parent;
@@ -953,7 +1064,7 @@ function $462841de7cc5b715$var$walkUpFrom(node, level) {
953
1064
  let drop = node;
954
1065
  while(drop.parent && drop.level > level)drop = drop.parent;
955
1066
  const parentId = drop.parent?.id || null;
956
- const index = $eb5355379510ac9b$export$305f7d4e9d4624f2(drop) + 1;
1067
+ const index = (0, $eb5355379510ac9b$export$305f7d4e9d4624f2)(drop) + 1;
957
1068
  return {
958
1069
  parentId: parentId,
959
1070
  index: index
@@ -967,7 +1078,7 @@ function $462841de7cc5b715$export$f502ca02ebb85a1c(args) {
967
1078
  drop: null,
968
1079
  cursor: $462841de7cc5b715$var$noCursor()
969
1080
  };
970
- /* Hovering over the middle of a folder */ if (node && $eb5355379510ac9b$export$769c5e872f5f8638(node) && hover.inMiddle) return {
1081
+ /* Hovering over the middle of a folder */ if (node && node.isInternal && hover.inMiddle) return {
971
1082
  drop: $462841de7cc5b715$var$dropAt(node.id, 0),
972
1083
  cursor: $462841de7cc5b715$var$highlightCursor(node.id)
973
1084
  };
@@ -975,7 +1086,7 @@ function $462841de7cc5b715$export$f502ca02ebb85a1c(args) {
975
1086
  drop: $462841de7cc5b715$var$dropAt(below?.parent?.id, 0),
976
1087
  cursor: $462841de7cc5b715$var$lineCursor(0, 0)
977
1088
  };
978
- /* The above node is an item or a closed folder */ if ($eb5355379510ac9b$export$5318634f2ee07019(above) || $eb5355379510ac9b$export$4210f5ea57fbae57(above)) {
1089
+ /* The above node is an item or a closed folder */ if ((0, $eb5355379510ac9b$export$5318634f2ee07019)(above) || (0, $eb5355379510ac9b$export$4210f5ea57fbae57)(above)) {
979
1090
  const level = $462841de7cc5b715$var$getDropLevel(hover, above, below, args.indent);
980
1091
  return {
981
1092
  drop: $462841de7cc5b715$var$walkUpFrom(above, level),
@@ -989,376 +1100,1240 @@ function $462841de7cc5b715$export$f502ca02ebb85a1c(args) {
989
1100
  }
990
1101
 
991
1102
 
992
- function $6c0a9a91d5e7ff45$export$5a6c424b1725f44f() {
993
- const tree = $6723c76b9de38fd1$export$367b0f2231a90ba0();
994
- // In case we drop an item at the bottom of the list
995
- const [, drop1] = $foSVk$reactdnd.useDrop(()=>({
1103
+ function $cf8ebdb33758b119$export$57afafec4637d997(el, node) {
1104
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
1105
+ const [_, dropRef] = (0, $foSVk$reactdnd.useDrop)(()=>({
996
1106
  accept: "NODE",
997
- hover: (item, m)=>{
998
- if (!m.isOver({
999
- shallow: true
1000
- })) return;
1107
+ canDrop: (item, m)=>{
1108
+ if (node.tree.isFiltered) return false;
1001
1109
  const offset = m.getClientOffset();
1002
- if (!tree.listEl.current || !offset) return;
1003
- const { cursor: cursor } = $462841de7cc5b715$export$f502ca02ebb85a1c({
1004
- element: tree.listEl.current,
1110
+ if (!el.current || !offset) return false;
1111
+ const { drop: drop } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
1112
+ element: el.current,
1005
1113
  offset: offset,
1006
1114
  indent: tree.indent,
1007
- node: null,
1008
- prevNode: tree.visibleNodes[tree.visibleNodes.length - 1],
1009
- nextNode: null
1115
+ node: node,
1116
+ prevNode: node.prev,
1117
+ nextNode: node.next
1010
1118
  });
1011
- if (cursor) tree.showCursor(cursor);
1119
+ if (!drop) return false;
1120
+ const dropParent = tree.get(drop.parentId) ?? tree.root;
1121
+ for (let id of item.dragIds){
1122
+ const drag = tree.get(id);
1123
+ if (!drag) return false;
1124
+ if (!dropParent) return false;
1125
+ if (drag.isInternal && (0, $eb5355379510ac9b$export$1e38f72c6c546f70)(dropParent, drag)) return false;
1126
+ }
1127
+ return true;
1012
1128
  },
1013
- canDrop: (item, m)=>{
1014
- return m.isOver({
1015
- shallow: true
1016
- });
1129
+ hover: (item, m)=>{
1130
+ if (m.canDrop()) {
1131
+ const offset = m.getClientOffset();
1132
+ if (!el.current || !offset) return;
1133
+ const { cursor: cursor } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
1134
+ element: el.current,
1135
+ offset: offset,
1136
+ indent: tree.indent,
1137
+ node: node,
1138
+ prevNode: node.prev,
1139
+ nextNode: node.next
1140
+ });
1141
+ if (cursor) tree.showCursor(cursor);
1142
+ } else tree.hideCursor();
1017
1143
  },
1018
1144
  drop: (item, m)=>{
1019
- if (m.didDrop()) return;
1020
1145
  const offset = m.getClientOffset();
1021
- if (!tree.listEl.current || !offset) return;
1022
- const { drop: drop } = $462841de7cc5b715$export$f502ca02ebb85a1c({
1023
- element: tree.listEl.current,
1146
+ if (!el.current || !offset) return;
1147
+ const { drop: drop } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
1148
+ element: el.current,
1024
1149
  offset: offset,
1025
1150
  indent: tree.indent,
1026
- node: null,
1027
- prevNode: tree.visibleNodes[tree.visibleNodes.length - 1],
1028
- nextNode: null
1151
+ node: node,
1152
+ prevNode: node.prev,
1153
+ nextNode: node.next
1029
1154
  });
1030
1155
  return drop;
1031
1156
  }
1032
- })
1033
- , [
1034
- tree
1157
+ }), [
1158
+ node,
1159
+ el.current,
1160
+ tree.props
1035
1161
  ]);
1036
- drop1(tree.listEl);
1037
- }
1038
-
1039
-
1040
- function $df8d0340a995314b$export$a6ee728c3c6ef11d(props) {
1041
- $6c0a9a91d5e7ff45$export$5a6c424b1725f44f();
1042
- return props.children;
1162
+ return dropRef;
1043
1163
  }
1044
1164
 
1045
1165
 
1046
1166
 
1047
1167
 
1168
+ function $3105f2bcc0822e0d$export$d75ab90b05ebbfaa(index) {
1169
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
1170
+ const original = tree.at(index);
1171
+ if (!original) throw new Error(`Could not find node for index: ${index}`);
1172
+ return (0, $foSVk$react.useMemo)(()=>{
1173
+ const fresh = original.clone();
1174
+ tree.visibleNodes[index] = fresh; // sneaky
1175
+ return fresh;
1176
+ // Return a fresh instance if the state values change
1177
+ }, [
1178
+ ...Object.values(original.state),
1179
+ original
1180
+ ]);
1181
+ }
1048
1182
 
1049
1183
 
1184
+ const $37e3f46f8fd1101f$export$a9754b3c8daa5172 = /*#__PURE__*/ (0, ($parcel$interopDefault($foSVk$react))).memo(function RowContainer({ index: index , style: style }) {
1185
+ /* When will the <Row> will re-render.
1186
+ *
1187
+ * The row component is memo'd so it will only render
1188
+ * when a new instance of the NodeApi class is passed
1189
+ * to it.
1190
+ *
1191
+ * The TreeApi instance is stable. It does not
1192
+ * change when the internal state changes.
1193
+ *
1194
+ * The TreeApi has all the references to the nodes.
1195
+ * We need to clone the nodes when their state
1196
+ * changes. The node class contains no state itself,
1197
+ * It always checks the tree for state. The tree's
1198
+ * state will always be up to date.
1199
+ */ (0, $d5cb84d44d1b8acc$export$83a4f9dc3b36edb8)(); // Re-render when tree props or visability changes
1200
+ const _ = (0, $d5cb84d44d1b8acc$export$fd23f19d5d8f3033)(); // So that we re-render appropriately
1201
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)(); // Tree already has the fresh state
1202
+ const node = (0, $3105f2bcc0822e0d$export$d75ab90b05ebbfaa)(index);
1203
+ const el = (0, $foSVk$react.useRef)(null);
1204
+ const dragRef = (0, $74bee24dbb0f3e2b$export$715c0d031ede7907)(node);
1205
+ const dropRef = (0, $cf8ebdb33758b119$export$57afafec4637d997)(el, node);
1206
+ const innerRef = (0, $foSVk$react.useCallback)((n)=>{
1207
+ el.current = n;
1208
+ dropRef(n);
1209
+ }, [
1210
+ dropRef
1211
+ ]);
1212
+ const indent = tree.indent * node.level;
1213
+ const nodeStyle = (0, $foSVk$react.useMemo)(()=>({
1214
+ paddingLeft: indent
1215
+ }), [
1216
+ indent
1217
+ ]);
1218
+ const rowStyle = (0, $foSVk$react.useMemo)(()=>({
1219
+ ...style,
1220
+ top: parseFloat(style.top) + ((tree.props.padding ?? tree.props.paddingTop) ?? 0)
1221
+ }), [
1222
+ style,
1223
+ tree.props.padding,
1224
+ tree.props.paddingTop
1225
+ ]);
1226
+ const rowAttrs = {
1227
+ role: "treeitem",
1228
+ "aria-level": node.level,
1229
+ "aria-selected": node.isSelected,
1230
+ style: rowStyle,
1231
+ tabIndex: -1
1232
+ };
1233
+ (0, $foSVk$react.useEffect)(()=>{
1234
+ if (!node.isEditing && node.isFocused) el.current?.focus();
1235
+ }, [
1236
+ node.isEditing,
1237
+ node.isFocused,
1238
+ el.current
1239
+ ]);
1240
+ const Node = tree.renderNode;
1241
+ const Row = tree.renderRow;
1242
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)(Row, {
1243
+ node: node,
1244
+ innerRef: innerRef,
1245
+ attrs: rowAttrs,
1246
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)(Node, {
1247
+ node: node,
1248
+ tree: tree,
1249
+ style: nodeStyle,
1250
+ dragHandle: dragRef
1251
+ })
1252
+ });
1253
+ });
1050
1254
 
1051
1255
 
1052
-
1053
- function $8fbadd7be430f501$export$ef961593063b03e8() {
1054
- const tree = $6723c76b9de38fd1$export$367b0f2231a90ba0();
1055
- const cursor = tree.state.cursor;
1056
- if (!cursor || cursor.type !== "line") return null;
1057
- const indent = tree.indent;
1058
- const top = tree.rowHeight * cursor.index;
1059
- const left = indent * cursor.level;
1060
- return tree.renderDropCursor({
1061
- top: top,
1062
- left: left,
1063
- indent: indent
1256
+ let $bb9a1e34249689ac$var$focusSearchTerm = "";
1257
+ let $bb9a1e34249689ac$var$timeoutId = null;
1258
+ function $bb9a1e34249689ac$export$ff4858a4110d9246() {
1259
+ (0, $d5cb84d44d1b8acc$export$83a4f9dc3b36edb8)();
1260
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
1261
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)("div", {
1262
+ style: {
1263
+ height: tree.height,
1264
+ width: tree.width,
1265
+ minHeight: 0,
1266
+ minWidth: 0
1267
+ },
1268
+ onContextMenu: tree.props.onContextMenu,
1269
+ onClick: tree.props.onClick,
1270
+ tabIndex: 0,
1271
+ onFocus: (e)=>{
1272
+ if (!e.currentTarget.contains(e.relatedTarget)) tree.onFocus();
1273
+ },
1274
+ onBlur: (e)=>{
1275
+ if (!e.currentTarget.contains(e.relatedTarget)) tree.onBlur();
1276
+ },
1277
+ onKeyDown: (e)=>{
1278
+ if (tree.isEditing) return;
1279
+ if (e.key === "Backspace") {
1280
+ if (!tree.props.onDelete) return;
1281
+ const ids = Array.from(tree.selectedIds);
1282
+ if (ids.length > 1) {
1283
+ let nextFocus = tree.mostRecentNode;
1284
+ while(nextFocus && nextFocus.isSelected)nextFocus = nextFocus.nextSibling;
1285
+ if (!nextFocus) nextFocus = tree.lastNode;
1286
+ tree.focus(nextFocus, {
1287
+ scroll: false
1288
+ });
1289
+ tree.delete(Array.from(ids));
1290
+ } else {
1291
+ const node = tree.focusedNode;
1292
+ if (node) {
1293
+ const sib = node.nextSibling;
1294
+ const parent = node.parent;
1295
+ tree.focus(sib || parent, {
1296
+ scroll: false
1297
+ });
1298
+ tree.delete(node);
1299
+ }
1300
+ }
1301
+ return;
1302
+ }
1303
+ if (e.key === "Tab" && !e.shiftKey) {
1304
+ e.preventDefault();
1305
+ (0, $eb5355379510ac9b$export$3b0237e8566c8d65)(e.currentTarget);
1306
+ return;
1307
+ }
1308
+ if (e.key === "Tab" && e.shiftKey) {
1309
+ e.preventDefault();
1310
+ (0, $eb5355379510ac9b$export$33b47db07a82b2fb)(e.currentTarget);
1311
+ return;
1312
+ }
1313
+ if (e.key === "ArrowDown" && !e.shiftKey && !e.metaKey) {
1314
+ e.preventDefault();
1315
+ const next = tree.nextNode;
1316
+ tree.focus(next);
1317
+ return;
1318
+ }
1319
+ if (e.key === "ArrowDown" && e.shiftKey) {
1320
+ e.preventDefault();
1321
+ const next1 = tree.nextNode;
1322
+ if (!next1) return;
1323
+ const current = tree.focusedNode;
1324
+ if (!current) tree.focus(tree.firstNode);
1325
+ else if (current.isSelected) tree.selectContiguous(next1);
1326
+ else tree.selectMulti(next1);
1327
+ return;
1328
+ }
1329
+ if (e.key === "ArrowUp" && !e.shiftKey) {
1330
+ e.preventDefault();
1331
+ tree.focus(tree.prevNode);
1332
+ return;
1333
+ }
1334
+ if (e.key === "ArrowUp" && e.shiftKey) {
1335
+ e.preventDefault();
1336
+ const prev = tree.prevNode;
1337
+ const current1 = tree.focusedNode;
1338
+ if (!prev) return;
1339
+ if (!current1) tree.focus(tree.lastNode); // ?
1340
+ else if (current1.isSelected) tree.selectContiguous(prev);
1341
+ else tree.selectMulti(prev);
1342
+ return;
1343
+ }
1344
+ if (e.key === "ArrowRight") {
1345
+ const node1 = tree.focusedNode;
1346
+ if (!node1) return;
1347
+ if (node1.isInternal && node1.isOpen) tree.focus(tree.nextNode);
1348
+ else if (node1.isInternal) tree.open(node1.id);
1349
+ return;
1350
+ }
1351
+ if (e.key === "ArrowLeft") {
1352
+ const node2 = tree.focusedNode;
1353
+ if (!node2 || node2.isRoot) return;
1354
+ if (node2.isInternal && node2.isOpen) tree.close(node2.id);
1355
+ else if (!node2.parent?.isRoot) tree.focus(node2.parent);
1356
+ return;
1357
+ }
1358
+ if (e.key === "a" && e.metaKey) {
1359
+ e.preventDefault();
1360
+ tree.selectAll();
1361
+ return;
1362
+ }
1363
+ if (e.key === "a" && !e.metaKey) {
1364
+ if (!tree.props.onCreate) return;
1365
+ tree.createLeaf();
1366
+ return;
1367
+ }
1368
+ if (e.key === "A" && !e.metaKey) {
1369
+ if (!tree.props.onCreate) return;
1370
+ tree.createInternal();
1371
+ return;
1372
+ }
1373
+ if (e.key === "Home") {
1374
+ // add shift keys
1375
+ e.preventDefault();
1376
+ tree.focus(tree.firstNode);
1377
+ return;
1378
+ }
1379
+ if (e.key === "End") {
1380
+ // add shift keys
1381
+ e.preventDefault();
1382
+ tree.focus(tree.lastNode);
1383
+ return;
1384
+ }
1385
+ if (e.key === "Enter") {
1386
+ if (!tree.props.onRename) return;
1387
+ setTimeout(()=>{
1388
+ if (tree.focusedNode) tree.edit(tree.focusedNode);
1389
+ });
1390
+ return;
1391
+ }
1392
+ if (e.key === " ") {
1393
+ e.preventDefault();
1394
+ const node3 = tree.focusedNode;
1395
+ if (!node3) return;
1396
+ if (node3.isLeaf) {
1397
+ node3.select();
1398
+ node3.activate();
1399
+ } else node3.toggle();
1400
+ return;
1401
+ }
1402
+ if (e.key === "*") {
1403
+ const node4 = tree.focusedNode;
1404
+ if (!node4) return;
1405
+ tree.openSiblings(node4);
1406
+ return;
1407
+ }
1408
+ if (e.key === "ArrowDown" && e.metaKey) {
1409
+ e.preventDefault();
1410
+ tree.select(tree.focusedNode);
1411
+ tree.activate(tree.focusedNode);
1412
+ return;
1413
+ }
1414
+ if (e.key === "PageUp") {
1415
+ e.preventDefault();
1416
+ tree.pageUp();
1417
+ return;
1418
+ }
1419
+ if (e.key === "PageDown") {
1420
+ e.preventDefault();
1421
+ tree.pageDown();
1422
+ }
1423
+ // If they type a sequence of characters
1424
+ // collect them. Reset them after a timeout.
1425
+ // Use it to search the tree for a node, then focus it.
1426
+ // Clean this up a bit later
1427
+ clearTimeout($bb9a1e34249689ac$var$timeoutId);
1428
+ $bb9a1e34249689ac$var$focusSearchTerm += e.key;
1429
+ $bb9a1e34249689ac$var$timeoutId = setTimeout(()=>{
1430
+ $bb9a1e34249689ac$var$focusSearchTerm = "";
1431
+ }, 600);
1432
+ const node5 = tree.visibleNodes.find((n)=>{
1433
+ // @ts-ignore
1434
+ const name = n.data.name;
1435
+ if (typeof name === "string") return name.toLowerCase().startsWith($bb9a1e34249689ac$var$focusSearchTerm);
1436
+ else return false;
1437
+ });
1438
+ if (node5) tree.focus(node5.id);
1439
+ },
1440
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $foSVk$reactwindow.FixedSizeList), {
1441
+ className: tree.props.className,
1442
+ outerRef: tree.listEl,
1443
+ itemCount: tree.visibleNodes.length,
1444
+ height: tree.height,
1445
+ width: tree.width,
1446
+ itemSize: tree.rowHeight,
1447
+ itemKey: (index)=>tree.visibleNodes[index]?.id || index,
1448
+ outerElementType: (0, $0e2adc7837d85ac3$export$70c2b8898b86d3ad),
1449
+ innerElementType: (0, $472f3c5b35f3bf96$export$a9af0da3ae60cd00),
1450
+ onScroll: tree.props.onScroll,
1451
+ onItemsRendered: tree.onItemsRendered.bind(tree),
1452
+ ref: tree.list,
1453
+ children: (0, $37e3f46f8fd1101f$export$a9754b3c8daa5172)
1454
+ })
1064
1455
  });
1065
1456
  }
1066
1457
 
1067
1458
 
1068
- const $0e2adc7837d85ac3$export$70c2b8898b86d3ad = /*#__PURE__*/ $foSVk$react.forwardRef(function Outer(props, ref) {
1069
- const { children: children , ...rest } = props;
1070
- const tree = $6723c76b9de38fd1$export$367b0f2231a90ba0();
1071
- return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsxs("div", {
1072
- // @ts-ignore
1073
- ref: ref,
1074
- ...rest,
1075
- onClick: tree.onClick,
1076
- onContextMenu: tree.onContextMenu,
1077
- children: [
1078
- /*#__PURE__*/ $foSVk$reactjsxruntime.jsx("div", {
1079
- style: {
1080
- height: tree.visibleNodes.length * tree.rowHeight,
1081
- width: "100%",
1082
- overflow: "hidden",
1083
- position: "absolute",
1084
- left: "0",
1085
- right: "0"
1086
- },
1087
- children: /*#__PURE__*/ $foSVk$reactjsxruntime.jsx($8fbadd7be430f501$export$ef961593063b03e8, {
1088
- })
1089
- }),
1090
- children
1091
- ]
1092
- }));
1093
- });
1459
+ function $07d1cda4da20dc54$export$5897d8d7c7a3d871(tree) {
1460
+ if (tree.isFiltered) return $07d1cda4da20dc54$var$flattenAndFilterTree(tree.root, tree.isMatch.bind(tree));
1461
+ else return $07d1cda4da20dc54$var$flattenTree(tree.root);
1462
+ }
1463
+ function $07d1cda4da20dc54$var$flattenTree(root) {
1464
+ const list = [];
1465
+ function collect(node) {
1466
+ if (node.level >= 0) list.push(node);
1467
+ if (node.isOpen) node.children?.forEach(collect);
1468
+ }
1469
+ collect(root);
1470
+ list.forEach($07d1cda4da20dc54$var$assignRowIndex);
1471
+ return list;
1472
+ }
1473
+ function $07d1cda4da20dc54$var$flattenAndFilterTree(root, isMatch) {
1474
+ function collect(node) {
1475
+ let result = [];
1476
+ const yes = !node.isRoot && isMatch(node);
1477
+ if (node.children) for (let child of node.children)result = result.concat(collect(child));
1478
+ if (result.length) {
1479
+ if (!node.isRoot) result.unshift(node);
1480
+ return result;
1481
+ }
1482
+ if (yes) return [
1483
+ node
1484
+ ];
1485
+ else return [];
1486
+ }
1487
+ const list = collect(root).filter((n)=>n.parent?.isOpen);
1488
+ list.forEach($07d1cda4da20dc54$var$assignRowIndex);
1489
+ return list;
1490
+ }
1491
+ function $07d1cda4da20dc54$var$assignRowIndex(node, index) {
1492
+ node.rowIndex = index;
1493
+ }
1094
1494
 
1095
1495
 
1496
+ const $db9e6e601e34ba08$export$c6d108d7c8095f19 = (nodes)=>{
1497
+ return nodes.reduce((map, node, index)=>{
1498
+ map[node.id] = index;
1499
+ return map;
1500
+ }, {});
1501
+ };
1096
1502
 
1097
1503
 
1504
+ const { safeRun: $5c74fef433be2b0a$var$safeRun , identify: $5c74fef433be2b0a$var$identify , identifyNull: $5c74fef433be2b0a$var$identifyNull } = $eb5355379510ac9b$exports;
1505
+ class $5c74fef433be2b0a$export$e2da3477247342d1 {
1506
+ constructor(store, props, list, listEl){
1507
+ this.store = store;
1508
+ this.props = props;
1509
+ this.list = list;
1510
+ this.listEl = listEl;
1511
+ this.visibleStartIndex = 0;
1512
+ this.visibleStopIndex = 0;
1513
+ /* Changes here must also be made in update() */ this.root = (0, $0d7f39915c1a8ae9$export$882461b6382ed46c)(this);
1514
+ this.visibleNodes = (0, $07d1cda4da20dc54$export$5897d8d7c7a3d871)(this);
1515
+ this.idToIndex = (0, $db9e6e601e34ba08$export$c6d108d7c8095f19)(this.visibleNodes);
1516
+ }
1517
+ /* Changes here must also be made in constructor() */ update(props) {
1518
+ this.props = props;
1519
+ this.root = (0, $0d7f39915c1a8ae9$export$882461b6382ed46c)(this);
1520
+ this.visibleNodes = (0, $07d1cda4da20dc54$export$5897d8d7c7a3d871)(this);
1521
+ this.idToIndex = (0, $db9e6e601e34ba08$export$c6d108d7c8095f19)(this.visibleNodes);
1522
+ }
1523
+ /* Store helpers */ dispatch(action) {
1524
+ return this.store.dispatch(action);
1525
+ }
1526
+ get state() {
1527
+ return this.store.getState();
1528
+ }
1529
+ get openState() {
1530
+ return this.state.nodes.open.unfiltered;
1531
+ }
1532
+ /* Tree Props */ get width() {
1533
+ return this.props.width || 300;
1534
+ }
1535
+ get height() {
1536
+ return this.props.height || 500;
1537
+ }
1538
+ get indent() {
1539
+ return this.props.indent || 24;
1540
+ }
1541
+ get rowHeight() {
1542
+ return this.props.rowHeight || 24;
1543
+ }
1544
+ get searchTerm() {
1545
+ return (this.props.searchTerm || "").trim();
1546
+ }
1547
+ get matchFn() {
1548
+ const match = this.props.searchMatch ?? ((node, term)=>{
1549
+ const string = JSON.stringify(Object.values(node.data));
1550
+ return string.toLocaleLowerCase().includes(term.toLocaleLowerCase());
1551
+ });
1552
+ return (node)=>match(node, this.searchTerm);
1553
+ }
1554
+ accessChildren(data) {
1555
+ const get = this.props.childrenAccessor || "children";
1556
+ return $eb5355379510ac9b$exports.access(data, get) ?? null;
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
+ }
1564
+ /* Node Access */ get firstNode() {
1565
+ return this.visibleNodes[0] ?? null;
1566
+ }
1567
+ get lastNode() {
1568
+ return this.visibleNodes[this.visibleNodes.length - 1] ?? null;
1569
+ }
1570
+ get focusedNode() {
1571
+ return this.get(this.state.nodes.focus.id) ?? null;
1572
+ }
1573
+ get mostRecentNode() {
1574
+ return this.get(this.state.nodes.selection.mostRecent) ?? null;
1575
+ }
1576
+ get nextNode() {
1577
+ const index = this.indexOf(this.focusedNode);
1578
+ if (index === null) return null;
1579
+ else return this.at(index + 1);
1580
+ }
1581
+ get prevNode() {
1582
+ const index = this.indexOf(this.focusedNode);
1583
+ if (index === null) return null;
1584
+ else return this.at(index - 1);
1585
+ }
1586
+ get(id) {
1587
+ if (!id) return null;
1588
+ if (id in this.idToIndex) return this.visibleNodes[this.idToIndex[id]] || null;
1589
+ else return null;
1590
+ }
1591
+ at(index) {
1592
+ return this.visibleNodes[index] || null;
1593
+ }
1594
+ nodesBetween(startId, endId) {
1595
+ if (startId === null || endId === null) return [];
1596
+ const index1 = this.indexOf(startId) ?? 0;
1597
+ const index2 = this.indexOf(endId);
1598
+ if (index2 === null) return [];
1599
+ const start = Math.min(index1, index2);
1600
+ const end = Math.max(index1, index2);
1601
+ return this.visibleNodes.slice(start, end + 1);
1602
+ }
1603
+ indexOf(id) {
1604
+ const key = $eb5355379510ac9b$exports.identifyNull(id);
1605
+ if (!key) return null;
1606
+ return this.idToIndex[key];
1607
+ }
1608
+ /* Data Operations */ get editingId() {
1609
+ return this.state.nodes.edit.id;
1610
+ }
1611
+ createInternal() {
1612
+ return this.create("internal");
1613
+ }
1614
+ createLeaf() {
1615
+ return this.create("leaf");
1616
+ }
1617
+ async create(type) {
1618
+ let index;
1619
+ let parentId;
1620
+ const focus = this.focusedNode;
1621
+ if (focus && focus.parent) {
1622
+ if (focus.isInternal && focus.isOpen) {
1623
+ parentId = focus.id;
1624
+ index = 0;
1625
+ } else {
1626
+ index = focus.childIndex + 1;
1627
+ parentId = focus.parent.isRoot ? null : focus.parent.id;
1628
+ }
1629
+ } else {
1630
+ index = this.root?.children?.length || -1;
1631
+ parentId = null;
1632
+ }
1633
+ const data = await $5c74fef433be2b0a$var$safeRun(this.props.onCreate, {
1634
+ parentId: parentId,
1635
+ index: index,
1636
+ type: type
1637
+ });
1638
+ if (data) {
1639
+ this.focus(data);
1640
+ setTimeout(()=>{
1641
+ this.edit(data).then(()=>{
1642
+ this.select(data);
1643
+ this.activate(data);
1644
+ });
1645
+ });
1646
+ }
1647
+ }
1648
+ async delete(node) {
1649
+ if (!node) return;
1650
+ const nodes = Array.isArray(node) ? node : [
1651
+ node
1652
+ ];
1653
+ const ids = nodes.map($5c74fef433be2b0a$var$identify);
1654
+ await $5c74fef433be2b0a$var$safeRun(this.props.onDelete, {
1655
+ ids: ids
1656
+ });
1657
+ }
1658
+ edit(node) {
1659
+ const id = $5c74fef433be2b0a$var$identify(node);
1660
+ this.resolveEdit({
1661
+ cancelled: true
1662
+ });
1663
+ this.scrollTo(id);
1664
+ this.dispatch((0, $1297c48a54b69bac$export$e1a8e267487c59d1)(id));
1665
+ return new Promise((resolve)=>{
1666
+ $5c74fef433be2b0a$export$e2da3477247342d1.editPromise = resolve;
1667
+ });
1668
+ }
1669
+ async submit(node, value) {
1670
+ if (!node) return;
1671
+ const id = $5c74fef433be2b0a$var$identify(node);
1672
+ await $5c74fef433be2b0a$var$safeRun(this.props.onRename, {
1673
+ id: id,
1674
+ name: value
1675
+ });
1676
+ this.dispatch((0, $1297c48a54b69bac$export$e1a8e267487c59d1)(null));
1677
+ this.resolveEdit({
1678
+ cancelled: false,
1679
+ value: value
1680
+ });
1681
+ setTimeout(()=>this.onFocus()); // Return focus to element;
1682
+ }
1683
+ reset() {
1684
+ this.dispatch((0, $1297c48a54b69bac$export$e1a8e267487c59d1)(null));
1685
+ this.resolveEdit({
1686
+ cancelled: true
1687
+ });
1688
+ setTimeout(()=>this.onFocus()); // Return focus to element;
1689
+ }
1690
+ activate(id) {
1691
+ const node = this.get($5c74fef433be2b0a$var$identifyNull(id));
1692
+ if (!node) return;
1693
+ $5c74fef433be2b0a$var$safeRun(this.props.onActivate, node);
1694
+ }
1695
+ resolveEdit(value) {
1696
+ const resolve = $5c74fef433be2b0a$export$e2da3477247342d1.editPromise;
1697
+ if (resolve) resolve(value);
1698
+ $5c74fef433be2b0a$export$e2da3477247342d1.editPromise = null;
1699
+ }
1700
+ /* Focus and Selection */ get selectedIds() {
1701
+ return this.state.nodes.selection.ids;
1702
+ }
1703
+ get selectedNodes() {
1704
+ let nodes = [];
1705
+ for (let id of Array.from(this.selectedIds)){
1706
+ const node = this.get(id);
1707
+ if (node) nodes.push(node);
1708
+ }
1709
+ return nodes;
1710
+ }
1711
+ focus(node, opts = {}) {
1712
+ if (!node) return;
1713
+ /* Focus is responsible for scrolling, while selection is
1714
+ * responsible for focus. If selectionFollowsFocus, then
1715
+ * just select it. */ if (this.props.selectionFollowsFocus) this.select(node);
1716
+ else {
1717
+ this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)($5c74fef433be2b0a$var$identify(node)));
1718
+ if (opts.scroll !== false) this.scrollTo(node);
1719
+ }
1720
+ }
1721
+ pageUp() {
1722
+ const start = this.visibleStartIndex;
1723
+ const stop = this.visibleStopIndex;
1724
+ const page = stop - start;
1725
+ let index = this.focusedNode?.rowIndex ?? 0;
1726
+ if (index > start) index = start;
1727
+ else index = Math.max(start - page, 0);
1728
+ this.focus(this.at(index));
1729
+ }
1730
+ pageDown() {
1731
+ const start = this.visibleStartIndex;
1732
+ const stop = this.visibleStopIndex;
1733
+ const page = stop - start;
1734
+ let index = this.focusedNode?.rowIndex ?? 0;
1735
+ if (index < stop) index = stop;
1736
+ else index = Math.min(index + page, this.visibleNodes.length - 1);
1737
+ this.focus(this.at(index));
1738
+ }
1739
+ select(node, opts = {}) {
1740
+ if (!node) return;
1741
+ const id = $5c74fef433be2b0a$var$identify(node);
1742
+ this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)(id));
1743
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).only(id));
1744
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(id));
1745
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(id));
1746
+ this.scrollTo(id, opts.align);
1747
+ $5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
1748
+ }
1749
+ deselect(node) {
1750
+ if (!node) return;
1751
+ const id = $5c74fef433be2b0a$var$identify(node);
1752
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).remove(id));
1753
+ }
1754
+ selectMulti(identity) {
1755
+ const node = this.get($5c74fef433be2b0a$var$identifyNull(identity));
1756
+ if (!node) return;
1757
+ this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)(node.id));
1758
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).add(node.id));
1759
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(node.id));
1760
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(node.id));
1761
+ this.scrollTo(node);
1762
+ $5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
1763
+ }
1764
+ selectContiguous(identity) {
1765
+ if (!identity) return;
1766
+ const id = $5c74fef433be2b0a$var$identify(identity);
1767
+ const { anchor: anchor , mostRecent: mostRecent } = this.state.nodes.selection;
1768
+ this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)(id));
1769
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).remove(this.nodesBetween(anchor, mostRecent)));
1770
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).add(this.nodesBetween(anchor, $5c74fef433be2b0a$var$identifyNull(id))));
1771
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(id));
1772
+ this.scrollTo(id);
1773
+ $5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
1774
+ }
1775
+ deselectAll() {
1776
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).clear());
1777
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(null));
1778
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(null));
1779
+ $5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
1780
+ }
1781
+ selectAll() {
1782
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).set(new Set(Object.keys(this.idToIndex))));
1783
+ this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)(this.lastNode?.id));
1784
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).anchor(this.firstNode));
1785
+ this.dispatch((0, $58f9381615aa3d17$export$e324594224ef24da).mostRecent(this.lastNode));
1786
+ $5c74fef433be2b0a$var$safeRun(this.props.onSelect, this.selectedNodes);
1787
+ }
1788
+ /* Drag and Drop */ get cursorParentId() {
1789
+ const { cursor: cursor } = this.state.dnd;
1790
+ switch(cursor.type){
1791
+ case "highlight":
1792
+ return cursor.id;
1793
+ default:
1794
+ return null;
1795
+ }
1796
+ }
1797
+ get cursorOverFolder() {
1798
+ return this.state.dnd.cursor.type === "highlight";
1799
+ }
1800
+ hideCursor() {
1801
+ this.dispatch((0, $7d98f5b84ecaa66b$export$e324594224ef24da).cursor({
1802
+ type: "none"
1803
+ }));
1804
+ }
1805
+ showCursor(cursor) {
1806
+ this.dispatch((0, $7d98f5b84ecaa66b$export$e324594224ef24da).cursor(cursor));
1807
+ }
1808
+ /* Visibility */ open(identity) {
1809
+ const id = $5c74fef433be2b0a$var$identifyNull(identity);
1810
+ if (!id) return;
1811
+ this.dispatch((0, $d519ceb3313d9d0e$export$e324594224ef24da).open(id, this.isFiltered));
1812
+ }
1813
+ close(identity) {
1814
+ const id = $5c74fef433be2b0a$var$identifyNull(identity);
1815
+ if (!id) return;
1816
+ this.dispatch((0, $d519ceb3313d9d0e$export$e324594224ef24da).close(id, this.isFiltered));
1817
+ }
1818
+ toggle(identity) {
1819
+ const id = $5c74fef433be2b0a$var$identifyNull(identity);
1820
+ if (!id) return;
1821
+ return this.isOpen(id) ? this.close(id) : this.open(id);
1822
+ }
1823
+ openParents(identity) {
1824
+ const id = $5c74fef433be2b0a$var$identifyNull(identity);
1825
+ if (!id) return;
1826
+ const node = $eb5355379510ac9b$exports.dfs(this.root, id);
1827
+ let parent = node?.parent;
1828
+ while(parent){
1829
+ this.open(parent.id);
1830
+ parent = parent.parent;
1831
+ }
1832
+ }
1833
+ openSiblings(node) {
1834
+ const parent = node.parent;
1835
+ if (!parent) this.toggle(node.id);
1836
+ else if (parent.children) {
1837
+ const isOpen = node.isOpen;
1838
+ for (let sibling of parent.children)if (sibling.isInternal) isOpen ? this.close(sibling.id) : this.open(sibling.id);
1839
+ this.scrollTo(this.focusedNode);
1840
+ }
1841
+ }
1842
+ /* Scrolling */ scrollTo(identity, align = "smart") {
1843
+ if (!identity) return;
1844
+ const id = $5c74fef433be2b0a$var$identify(identity);
1845
+ this.openParents(id);
1846
+ return $eb5355379510ac9b$exports.waitFor(()=>id in this.idToIndex).then(()=>{
1847
+ const index = this.idToIndex[id];
1848
+ if (index === undefined) return;
1849
+ this.list.current?.scrollToItem(index, align);
1850
+ }).catch(()=>{
1851
+ console.log(`Id: ${id} never appeared in the list.`);
1852
+ });
1853
+ }
1854
+ /* State Checks */ get isEditing() {
1855
+ return this.state.nodes.edit.id !== null;
1856
+ }
1857
+ get isFiltered() {
1858
+ return !!this.props.searchTerm?.trim();
1859
+ }
1860
+ get hasFocus() {
1861
+ return this.state.nodes.focus.treeFocused;
1862
+ }
1863
+ isSelected(id) {
1864
+ if (!id) return false;
1865
+ return this.state.nodes.selection.ids.has(id);
1866
+ }
1867
+ isOpen(id) {
1868
+ if (!id) return false;
1869
+ if (id === (0, $0d7f39915c1a8ae9$export$ec71a3379b43ae5c)) return true;
1870
+ const def = this.props.openByDefault ?? true;
1871
+ if (this.isFiltered) return this.state.nodes.open.filtered[id] ?? true; // Filtered folders are always opened by default
1872
+ else return this.state.nodes.open.unfiltered[id] ?? def;
1873
+ }
1874
+ isDraggable(data) {
1875
+ const check = this.props.disableDrag || (()=>false);
1876
+ return !$eb5355379510ac9b$exports.access(data, check) ?? true;
1877
+ }
1878
+ isDroppable(data) {
1879
+ const check = this.props.disableDrop || (()=>false);
1880
+ return !$eb5355379510ac9b$exports.access(data, check) ?? true;
1881
+ }
1882
+ isDragging(node) {
1883
+ const id = $5c74fef433be2b0a$var$identifyNull(node);
1884
+ if (!id) return false;
1885
+ return this.state.nodes.drag.id === id;
1886
+ }
1887
+ isFocused(id) {
1888
+ return this.hasFocus && this.state.nodes.focus.id === id;
1889
+ }
1890
+ isMatch(node) {
1891
+ return this.matchFn(node);
1892
+ }
1893
+ willReceiveDrop(node) {
1894
+ const id = $5c74fef433be2b0a$var$identifyNull(node);
1895
+ if (!id) return false;
1896
+ return id === this.state.nodes.drag.idWillReceiveDrop;
1897
+ }
1898
+ /* Tree Event Handlers */ onFocus() {
1899
+ const node = this.focusedNode || this.firstNode;
1900
+ if (node) this.dispatch((0, $61ef7f2c3c9633e7$export$d7ddd398f22d79ef)(node.id));
1901
+ }
1902
+ onBlur() {
1903
+ this.dispatch((0, $61ef7f2c3c9633e7$export$6b6c976e46a06288)());
1904
+ }
1905
+ onItemsRendered(args) {
1906
+ this.visibleStartIndex = args.visibleStartIndex;
1907
+ this.visibleStopIndex = args.visibleStopIndex;
1908
+ }
1909
+ /* Get Renderers */ get renderContainer() {
1910
+ return this.props.renderContainer || (0, $bb9a1e34249689ac$export$ff4858a4110d9246);
1911
+ }
1912
+ get renderRow() {
1913
+ return this.props.renderRow || (0, $ff6862a32cc2ac81$export$f9c541e71856c524);
1914
+ }
1915
+ get renderNode() {
1916
+ return this.props.children || (0, $3240a4b0b5620968$export$909e23cbfbbd3351);
1917
+ }
1918
+ get renderDragPreview() {
1919
+ return this.props.renderDragPreview || (0, $6e3db8c23c41dfc9$export$84e211ad8431a387);
1920
+ }
1921
+ get renderCursor() {
1922
+ return this.props.renderCursor || (0, $c79fefb0d0a1d13b$export$6cb3c16721363d11);
1923
+ }
1924
+ }
1098
1925
 
1099
1926
 
1100
1927
 
1101
1928
 
1102
1929
 
1103
- function $74bee24dbb0f3e2b$export$715c0d031ede7907(node) {
1104
- const tree = $6723c76b9de38fd1$export$367b0f2231a90ba0();
1105
- const ids = tree.getSelectedIds();
1106
- const [{ isDragging: isDragging }, ref, preview] = $foSVk$reactdnd.useDrag(()=>({
1107
- canDrag: ()=>node.isDraggable
1108
- ,
1109
- type: "NODE",
1110
- item: ()=>({
1111
- id: node.id,
1112
- dragIds: tree.isSelected(node.rowIndex) ? ids : [
1113
- node.id
1114
- ]
1115
- })
1116
- ,
1117
- collect: (m)=>({
1118
- isDragging: m.isDragging()
1119
- })
1120
- ,
1121
- end: (item, monitor)=>{
1122
- tree.hideCursor();
1123
- const drop = monitor.getDropResult();
1124
- if (drop && drop.parentId) {
1125
- tree.onMove(item.dragIds, drop.parentId, drop.index);
1126
- tree.onToggle(drop.parentId, true);
1127
- }
1128
- }
1129
- })
1130
- , [
1131
- ids,
1132
- node
1930
+
1931
+
1932
+
1933
+
1934
+ function $2f73c1963cd9aa06$export$1650419e431d3ba3(state = {
1935
+ id: null,
1936
+ idWillReceiveDrop: null
1937
+ }, action) {
1938
+ switch(action.type){
1939
+ case "DND_DRAG_START":
1940
+ return {
1941
+ ...state,
1942
+ id: action.id
1943
+ };
1944
+ case "DND_DRAG_END":
1945
+ return {
1946
+ ...state,
1947
+ id: null
1948
+ };
1949
+ case "DND_CURSOR":
1950
+ const c = action.cursor;
1951
+ if (c.type === "highlight" && c.id !== state.idWillReceiveDrop) return {
1952
+ ...state,
1953
+ idWillReceiveDrop: c.id
1954
+ };
1955
+ else if (c.type !== "highlight" && state.idWillReceiveDrop !== null) return {
1956
+ ...state,
1957
+ idWillReceiveDrop: null
1958
+ };
1959
+ else return state;
1960
+ default:
1961
+ return state;
1962
+ }
1963
+ }
1964
+
1965
+
1966
+ const $cdb8f316fadc608f$export$a8a69c316169e623 = (0, $foSVk$redux.combineReducers)({
1967
+ nodes: (0, $foSVk$redux.combineReducers)({
1968
+ focus: $61ef7f2c3c9633e7$export$1650419e431d3ba3,
1969
+ edit: $1297c48a54b69bac$export$1650419e431d3ba3,
1970
+ open: $d519ceb3313d9d0e$export$1650419e431d3ba3,
1971
+ selection: $58f9381615aa3d17$export$1650419e431d3ba3,
1972
+ drag: $2f73c1963cd9aa06$export$1650419e431d3ba3
1973
+ }),
1974
+ dnd: $7d98f5b84ecaa66b$export$1650419e431d3ba3
1975
+ });
1976
+
1977
+
1978
+
1979
+
1980
+
1981
+
1982
+ const $9511ad6af37da13b$var$SERVER_STATE = (0, $9d556ecd8e421ffe$export$d4c72bab9d6cc13a)();
1983
+ function $9511ad6af37da13b$export$c49dab5eb1b4ce0c({ treeProps: treeProps , imperativeHandle: imperativeHandle , children: children }) {
1984
+ const list = (0, $foSVk$react.useRef)(null);
1985
+ const listEl = (0, $foSVk$react.useRef)(null);
1986
+ const store = (0, $foSVk$react.useRef)((0, $foSVk$redux.createStore)((0, $cdb8f316fadc608f$export$a8a69c316169e623), (0, $9d556ecd8e421ffe$export$d4c72bab9d6cc13a)(treeProps)));
1987
+ const state = (0, $foSVk$usesyncexternalstoreshim.useSyncExternalStore)(store.current.subscribe, store.current.getState, ()=>$9511ad6af37da13b$var$SERVER_STATE);
1988
+ /* The tree api object is stable. */ const api = (0, $foSVk$react.useMemo)(()=>{
1989
+ return new (0, $5c74fef433be2b0a$export$e2da3477247342d1)(store.current, treeProps, list, listEl);
1990
+ }, []);
1991
+ /* Make sure the tree instance stays in sync */ const updateCount = (0, $foSVk$react.useRef)(0);
1992
+ (0, $foSVk$react.useMemo)(()=>{
1993
+ updateCount.current += 1;
1994
+ api.update(treeProps);
1995
+ }, [
1996
+ ...Object.values(treeProps),
1997
+ state.nodes.open
1133
1998
  ]);
1134
- $foSVk$react.useEffect(()=>{
1135
- preview($foSVk$reactdndhtml5backend.getEmptyImage());
1999
+ /* Expose the tree api */ (0, $foSVk$react.useImperativeHandle)(imperativeHandle, ()=>api);
2000
+ /* Change selection based on props */ (0, $foSVk$react.useEffect)(()=>{
2001
+ if (api.props.selection) api.select(api.props.selection);
2002
+ else api.deselectAll();
1136
2003
  }, [
1137
- preview
2004
+ api.props.selection
1138
2005
  ]);
1139
- return [
1140
- {
1141
- isDragging: isDragging
1142
- },
1143
- ref
1144
- ];
2006
+ /* Clear visability for filtered nodes */ (0, $foSVk$react.useEffect)(()=>{
2007
+ if (!api.props.searchTerm) store.current.dispatch((0, $d519ceb3313d9d0e$export$e324594224ef24da).clear(true));
2008
+ }, [
2009
+ api.props.searchTerm
2010
+ ]);
2011
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $d5cb84d44d1b8acc$export$feef243b04ff4151).Provider, {
2012
+ value: api,
2013
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $d5cb84d44d1b8acc$export$d0c71bc5e3e2d897).Provider, {
2014
+ value: updateCount.current,
2015
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $d5cb84d44d1b8acc$export$f6d467aa8b3786af).Provider, {
2016
+ value: state.nodes,
2017
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $d5cb84d44d1b8acc$export$2d5c5ceac203fc1e).Provider, {
2018
+ value: state.dnd,
2019
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $foSVk$reactdnd.DndProvider), {
2020
+ backend: (0, $foSVk$reactdndhtml5backend.HTML5Backend),
2021
+ options: {
2022
+ rootElement: api.props.dndRootElement || undefined
2023
+ },
2024
+ children: children
2025
+ })
2026
+ })
2027
+ })
2028
+ })
2029
+ });
1145
2030
  }
1146
2031
 
1147
2032
 
1148
2033
 
1149
2034
 
1150
2035
 
1151
-
1152
- function $cf8ebdb33758b119$export$57afafec4637d997(el, node, prev, next) {
1153
- const tree = $6723c76b9de38fd1$export$367b0f2231a90ba0();
1154
- return $foSVk$reactdnd.useDrop(()=>({
2036
+ function $6c0a9a91d5e7ff45$export$5a6c424b1725f44f() {
2037
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
2038
+ // In case we drop an item at the bottom of the list
2039
+ const [, drop] = (0, $foSVk$reactdnd.useDrop)(()=>({
1155
2040
  accept: "NODE",
1156
- canDrop: (item)=>{
1157
- for (let id of item.dragIds){
1158
- const drag = tree.getNode(id);
1159
- if (!drag) return false;
1160
- if ($eb5355379510ac9b$export$769c5e872f5f8638(drag) && $eb5355379510ac9b$export$1e38f72c6c546f70(node, drag)) return false;
1161
- }
1162
- return true;
1163
- },
1164
2041
  hover: (item, m)=>{
1165
- if (m.canDrop()) {
1166
- const offset = m.getClientOffset();
1167
- if (!el.current || !offset) return;
1168
- const { cursor: cursor } = $462841de7cc5b715$export$f502ca02ebb85a1c({
1169
- element: el.current,
1170
- offset: offset,
1171
- indent: tree.indent,
1172
- node: node,
1173
- prevNode: prev,
1174
- nextNode: next
1175
- });
1176
- if (cursor) tree.showCursor(cursor);
1177
- } else tree.hideCursor();
2042
+ if (!m.isOver({
2043
+ shallow: true
2044
+ })) return;
2045
+ const offset = m.getClientOffset();
2046
+ if (!tree.listEl.current || !offset) return;
2047
+ const { cursor: cursor } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
2048
+ element: tree.listEl.current,
2049
+ offset: offset,
2050
+ indent: tree.indent,
2051
+ node: null,
2052
+ prevNode: tree.visibleNodes[tree.visibleNodes.length - 1],
2053
+ nextNode: null
2054
+ });
2055
+ if (cursor) tree.showCursor(cursor);
2056
+ },
2057
+ canDrop: (item, m)=>{
2058
+ return m.isOver({
2059
+ shallow: true
2060
+ });
1178
2061
  },
1179
2062
  drop: (item, m)=>{
2063
+ if (m.didDrop()) return;
1180
2064
  const offset = m.getClientOffset();
1181
- if (!el.current || !offset) return;
1182
- const { drop: drop } = $462841de7cc5b715$export$f502ca02ebb85a1c({
1183
- element: el.current,
2065
+ if (!tree.listEl.current || !offset) return;
2066
+ const { drop: drop } = (0, $462841de7cc5b715$export$f502ca02ebb85a1c)({
2067
+ element: tree.listEl.current,
1184
2068
  offset: offset,
1185
2069
  indent: tree.indent,
1186
- node: node,
1187
- prevNode: prev,
1188
- nextNode: next
2070
+ node: null,
2071
+ prevNode: tree.visibleNodes[tree.visibleNodes.length - 1],
2072
+ nextNode: null
1189
2073
  });
1190
2074
  return drop;
1191
2075
  }
1192
- })
1193
- , [
1194
- node,
1195
- prev,
1196
- el,
2076
+ }), [
1197
2077
  tree
1198
2078
  ]);
2079
+ drop(tree.listEl);
1199
2080
  }
1200
2081
 
1201
2082
 
1202
- const $9a2860bfaab93091$export$b59bdbef9ce70de2 = /*#__PURE__*/ ($parcel$interopDefault($foSVk$react)).memo(function $9a2860bfaab93091$export$b59bdbef9ce70de2({ index: index , style: style }) {
1203
- const realTree = $6723c76b9de38fd1$export$367b0f2231a90ba0();
1204
- const tree = $foSVk$react.useMemo(()=>realTree
1205
- , []);
1206
- tree.sync(realTree);
1207
- const node = tree.visibleNodes[index];
1208
- const next = tree.visibleNodes[index + 1] || null;
1209
- const prev = tree.visibleNodes[index - 1] || null;
1210
- const el = $foSVk$react.useRef(null);
1211
- const [{ isDragging: isDragging }, dragRef] = $74bee24dbb0f3e2b$export$715c0d031ede7907(node);
1212
- const [, dropRef] = $cf8ebdb33758b119$export$57afafec4637d997(el, node, prev, next);
1213
- const isEditing = node.id === tree.editingId;
1214
- const isSelected = tree.isSelected(index);
1215
- const nextSelected = next && tree.isSelected(index + 1);
1216
- const prevSelected = prev && tree.isSelected(index - 1);
1217
- const isHoveringOverChild = node.id === tree.cursorParentId;
1218
- const isOverFolder = node.id === tree.cursorParentId && tree.cursorOverFolder;
1219
- const isOpen = node.isOpen;
1220
- const indent = tree.indent * node.level;
1221
- const state = $foSVk$react.useMemo(()=>{
2083
+ function $df8d0340a995314b$export$a6ee728c3c6ef11d(props) {
2084
+ (0, $6c0a9a91d5e7ff45$export$5a6c424b1725f44f)();
2085
+ return props.children;
2086
+ }
2087
+
2088
+
2089
+
2090
+
2091
+
2092
+
2093
+ function $17a87d0a329a3eaa$export$cdf2ef3f6364d85() {
2094
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
2095
+ const Container = tree.props.renderContainer || (0, $bb9a1e34249689ac$export$ff4858a4110d9246);
2096
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $foSVk$reactjsxruntime.Fragment), {
2097
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)(Container, {})
2098
+ });
2099
+ }
2100
+
2101
+
2102
+
2103
+
2104
+
2105
+
2106
+ function $ed13b1d404b3872b$export$3e21b60650ec7e55() {
2107
+ const tree = (0, $d5cb84d44d1b8acc$export$367b0f2231a90ba0)();
2108
+ const { offset: offset , mouse: mouse , item: item , isDragging: isDragging } = (0, $foSVk$reactdnd.useDragLayer)((m)=>{
1222
2109
  return {
1223
- isEditing: isEditing,
1224
- isDragging: isDragging,
1225
- isSelectedStart: isSelected && !prevSelected,
1226
- isSelectedEnd: isSelected && !nextSelected,
1227
- isSelected: isSelected,
1228
- isHoveringOverChild: isHoveringOverChild,
1229
- isOpen: isOpen,
1230
- isOverFolder: isOverFolder
2110
+ offset: m.getSourceClientOffset(),
2111
+ mouse: m.getClientOffset(),
2112
+ item: m.getItem(),
2113
+ isDragging: m.isDragging()
1231
2114
  };
1232
- }, [
1233
- isEditing,
1234
- isSelected,
1235
- prevSelected,
1236
- nextSelected,
1237
- isHoveringOverChild,
1238
- isOpen,
1239
- isDragging,
1240
- isOverFolder,
1241
- ]);
1242
- const ref = $foSVk$react.useCallback((n)=>{
1243
- el.current = n;
1244
- dragRef(dropRef(n));
1245
- }, [
1246
- dragRef,
1247
- dropRef
1248
- ]);
1249
- const styles = $foSVk$react.useMemo(()=>({
1250
- row: {
1251
- ...style
1252
- },
1253
- indent: {
1254
- paddingLeft: indent
2115
+ });
2116
+ const DragPreview = tree.props.renderDragPreview || (0, $6e3db8c23c41dfc9$export$84e211ad8431a387);
2117
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)(DragPreview, {
2118
+ offset: offset,
2119
+ mouse: mouse,
2120
+ id: item?.id || null,
2121
+ dragIds: item?.dragIds || [],
2122
+ isDragging: isDragging
2123
+ });
2124
+ }
2125
+
2126
+
2127
+ var $2492d77b1ec82005$exports = {};
2128
+
2129
+ $parcel$export($2492d77b1ec82005$exports, "useSimpleTree", () => $2492d77b1ec82005$export$dcd27aa2043b2724);
2130
+
2131
+ var $ce2da9e8a36b0fcd$exports = {};
2132
+
2133
+ $parcel$export($ce2da9e8a36b0fcd$exports, "SimpleTree", () => $ce2da9e8a36b0fcd$export$e32206264f456dce);
2134
+ class $ce2da9e8a36b0fcd$export$e32206264f456dce {
2135
+ constructor(data){
2136
+ this.root = $ce2da9e8a36b0fcd$var$createRoot(data);
2137
+ }
2138
+ get data() {
2139
+ return this.root.children?.map((node)=>node.data) ?? [];
2140
+ }
2141
+ create(args) {
2142
+ const parent = args.parentId ? this.find(args.parentId) : this.root;
2143
+ if (!parent) return null;
2144
+ parent.addChild(args.data, args.index);
2145
+ }
2146
+ move(args) {
2147
+ const src = this.find(args.id);
2148
+ const parent = args.parentId ? this.find(args.parentId) : this.root;
2149
+ if (!src || !parent) return;
2150
+ parent.addChild(src.data, args.index);
2151
+ src.drop();
2152
+ }
2153
+ update(args) {
2154
+ const node = this.find(args.id);
2155
+ if (node) node.update(args.changes);
2156
+ }
2157
+ drop(args) {
2158
+ const node = this.find(args.id);
2159
+ if (node) node.drop();
2160
+ }
2161
+ find(id, node = this.root) {
2162
+ if (!node) return null;
2163
+ if (node.id === id) return node;
2164
+ if (node.children) {
2165
+ for (let child of node.children){
2166
+ const found = this.find(id, child);
2167
+ if (found) return found;
1255
2168
  }
1256
- })
1257
- , [
1258
- indent,
1259
- style
2169
+ return null;
2170
+ }
2171
+ return null;
2172
+ }
2173
+ }
2174
+ function $ce2da9e8a36b0fcd$var$createRoot(data) {
2175
+ const root = new $ce2da9e8a36b0fcd$var$SimpleNode({
2176
+ id: "ROOT"
2177
+ }, null);
2178
+ root.children = data.map((d)=>$ce2da9e8a36b0fcd$var$createNode(d, root));
2179
+ return root;
2180
+ }
2181
+ function $ce2da9e8a36b0fcd$var$createNode(data, parent) {
2182
+ const node = new $ce2da9e8a36b0fcd$var$SimpleNode(data, parent);
2183
+ if (data.children) node.children = data.children.map((d)=>$ce2da9e8a36b0fcd$var$createNode(d, node));
2184
+ return node;
2185
+ }
2186
+ class $ce2da9e8a36b0fcd$var$SimpleNode {
2187
+ constructor(data, parent){
2188
+ this.data = data;
2189
+ this.parent = parent;
2190
+ this.id = data.id;
2191
+ }
2192
+ hasParent() {
2193
+ return !!this.parent;
2194
+ }
2195
+ get childIndex() {
2196
+ return this.hasParent() ? this.parent.children.indexOf(this) : -1;
2197
+ }
2198
+ addChild(data, index) {
2199
+ const node = $ce2da9e8a36b0fcd$var$createNode(data, this);
2200
+ this.children = this.children ?? [];
2201
+ this.children.splice(index, 0, node);
2202
+ this.data.children = this.data.children ?? [];
2203
+ this.data.children.splice(index, 0, data);
2204
+ }
2205
+ removeChild(index) {
2206
+ this.children?.splice(index, 1);
2207
+ this.data.children?.splice(index, 1);
2208
+ }
2209
+ update(changes) {
2210
+ if (this.hasParent()) {
2211
+ const i = this.childIndex;
2212
+ this.parent.addChild({
2213
+ ...this.data,
2214
+ ...changes
2215
+ }, i);
2216
+ this.drop();
2217
+ }
2218
+ }
2219
+ drop() {
2220
+ if (this.hasParent()) this.parent.removeChild(this.childIndex);
2221
+ }
2222
+ }
2223
+
2224
+
2225
+ let $2492d77b1ec82005$var$nextId = 0;
2226
+ function $2492d77b1ec82005$export$dcd27aa2043b2724(initialData) {
2227
+ const [data, setData] = (0, $foSVk$react.useState)(initialData);
2228
+ const tree = (0, $foSVk$react.useMemo)(()=>new (0, $ce2da9e8a36b0fcd$export$e32206264f456dce)(data), [
2229
+ data
1260
2230
  ]);
1261
- const handlers = $foSVk$react.useMemo(()=>{
1262
- return {
1263
- select: (e, args = {
1264
- selectOnClick: true
1265
- })=>{
1266
- if (node.rowIndex === null) return;
1267
- if (args.selectOnClick || e.metaKey || e.shiftKey) tree.select(node.rowIndex, e.metaKey, e.shiftKey);
1268
- else tree.select(null, false, false);
1269
- },
1270
- toggle: (e)=>{
1271
- e.stopPropagation();
1272
- tree.onToggle(node.id, !node.isOpen);
1273
- },
1274
- edit: ()=>tree.edit(node.id)
1275
- ,
1276
- submit: (name)=>{
1277
- name.trim() ? tree.submit(node.id, name) : tree.reset(node.id);
1278
- },
1279
- reset: ()=>tree.reset(node.id)
2231
+ const onMove = (args)=>{
2232
+ for (const id of args.dragIds)tree.move({
2233
+ id: id,
2234
+ parentId: args.parentId,
2235
+ index: args.index
2236
+ });
2237
+ setData(tree.data);
2238
+ };
2239
+ const onRename = ({ name: name , id: id })=>{
2240
+ tree.update({
2241
+ id: id,
2242
+ changes: {
2243
+ name: name
2244
+ }
2245
+ });
2246
+ setData(tree.data);
2247
+ };
2248
+ const onCreate = ({ parentId: parentId , index: index , type: type })=>{
2249
+ const data = {
2250
+ id: `simple-tree-id-${$2492d77b1ec82005$var$nextId++}`,
2251
+ name: ""
1280
2252
  };
1281
- }, [
1282
- node,
1283
- tree
1284
- ]);
1285
- const Renderer = $foSVk$react.useMemo(()=>{
1286
- return(/*#__PURE__*/ ($parcel$interopDefault($foSVk$react)).memo(tree.renderer));
1287
- }, [
1288
- tree.renderer
1289
- ]);
1290
- return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsx(Renderer, {
1291
- innerRef: ref,
1292
- data: node.model,
1293
- styles: styles,
1294
- state: state,
1295
- handlers: handlers,
1296
- preview: false,
1297
- tree: tree
1298
- }));
1299
- });
2253
+ if (type === "internal") data.children = [];
2254
+ tree.create({
2255
+ parentId: parentId,
2256
+ index: index,
2257
+ data: data
2258
+ });
2259
+ setData(tree.data);
2260
+ return data;
2261
+ };
2262
+ const onDelete = (args)=>{
2263
+ args.ids.forEach((id)=>tree.drop({
2264
+ id: id
2265
+ }));
2266
+ setData(tree.data);
2267
+ };
2268
+ const controller = {
2269
+ onMove: onMove,
2270
+ onRename: onRename,
2271
+ onCreate: onCreate,
2272
+ onDelete: onDelete
2273
+ };
2274
+ return [
2275
+ data,
2276
+ controller
2277
+ ];
2278
+ }
1300
2279
 
1301
2280
 
1302
- function $07c00e593b4f3d62$export$54c2e3dc7acea9f5(props) {
1303
- const tree = $6723c76b9de38fd1$export$367b0f2231a90ba0();
1304
- return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsx("div", {
1305
- style: {
1306
- height: tree.height,
1307
- width: tree.width,
1308
- overflow: "hidden"
1309
- },
1310
- children: /*#__PURE__*/ $foSVk$reactjsxruntime.jsx($foSVk$reactwindow.FixedSizeList, {
1311
- className: props.className,
1312
- outerRef: tree.listEl,
1313
- itemCount: tree.visibleNodes.length,
1314
- height: tree.height,
1315
- width: tree.width,
1316
- itemSize: tree.rowHeight,
1317
- itemKey: (index)=>tree.visibleNodes[index]?.id || index
1318
- ,
1319
- outerElementType: $0e2adc7837d85ac3$export$70c2b8898b86d3ad,
1320
- ref: tree.list,
1321
- children: $9a2860bfaab93091$export$b59bdbef9ce70de2
1322
- })
1323
- }));
2281
+ function $8e1ae4dab2259e77$export$d227906824a13416(props) {
2282
+ if (props.initialData && props.data) throw new Error(`React Arborist Tree => Provide either a data or initialData prop, but not both.`);
2283
+ if (props.initialData && (props.onCreate || props.onDelete || props.onMove || props.onRename)) throw new Error(`React Arborist Tree => You passed the initialData prop along with a data handler.
2284
+ Use the data prop if you want to provide your own handlers.`);
2285
+ if (props.initialData) {
2286
+ /**
2287
+ * Let's break the rules of hooks here. If the initialData prop
2288
+ * is provided, we will assume it will not change for the life of
2289
+ * the component.
2290
+ *
2291
+ * We will provide the real data and the handlers to update it.
2292
+ * */ const [data, controller] = (0, $2492d77b1ec82005$export$dcd27aa2043b2724)(props.initialData);
2293
+ return {
2294
+ ...props,
2295
+ ...controller,
2296
+ data: data
2297
+ };
2298
+ } else return props;
1324
2299
  }
1325
2300
 
1326
2301
 
1327
- const $641461e16d1a2941$export$7fbedc92909ed28e = /*#__PURE__*/ $foSVk$react.forwardRef(function $641461e16d1a2941$export$7fbedc92909ed28e(props, ref) {
1328
- const root = $foSVk$react.useMemo(()=>$2d914ccbe0a16edd$export$9c537176392280a0(props.data, props.hideRoot, props.getChildren, props.isOpen, props.disableDrag, props.disableDrop, props.openByDefault)
1329
- , [
1330
- props.data,
1331
- props.hideRoot,
1332
- props.getChildren,
1333
- props.isOpen,
1334
- props.disableDrag,
1335
- props.disableDrop,
1336
- props.openByDefault,
1337
- ]);
1338
- return(/*#__PURE__*/ $foSVk$reactjsxruntime.jsx($59c6116b7d090f1c$export$6a399b2f7f12632c, {
1339
- treeProps: props,
2302
+ const $641461e16d1a2941$export$7fbedc92909ed28e = /*#__PURE__*/ (0, $foSVk$react.forwardRef)(function Tree(props, ref) {
2303
+ const treeProps = (0, $8e1ae4dab2259e77$export$d227906824a13416)(props);
2304
+ return /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsxs)((0, $9511ad6af37da13b$export$c49dab5eb1b4ce0c), {
2305
+ treeProps: treeProps,
1340
2306
  imperativeHandle: ref,
1341
- root: root,
1342
- children: /*#__PURE__*/ $foSVk$reactjsxruntime.jsxs($foSVk$reactdnd.DndProvider, {
1343
- backend: $foSVk$reactdndhtml5backend.HTML5Backend,
1344
- options: {
1345
- rootElement: props.dndRootElement || undefined
1346
- },
1347
- children: [
1348
- /*#__PURE__*/ $foSVk$reactjsxruntime.jsx($df8d0340a995314b$export$a6ee728c3c6ef11d, {
1349
- children: /*#__PURE__*/ $foSVk$reactjsxruntime.jsx($07c00e593b4f3d62$export$54c2e3dc7acea9f5, {
1350
- className: props.className
1351
- })
1352
- }),
1353
- /*#__PURE__*/ $foSVk$reactjsxruntime.jsx($8317ba945ccd0ce3$export$133773870222880f, {
1354
- })
1355
- ]
1356
- })
1357
- }));
2307
+ children: [
2308
+ /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $df8d0340a995314b$export$a6ee728c3c6ef11d), {
2309
+ children: /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $17a87d0a329a3eaa$export$cdf2ef3f6364d85), {})
2310
+ }),
2311
+ /*#__PURE__*/ (0, $foSVk$reactjsxruntime.jsx)((0, $ed13b1d404b3872b$export$3e21b60650ec7e55), {})
2312
+ ]
2313
+ });
1358
2314
  });
1359
2315
 
1360
2316
 
2317
+ var $73c61fb8fd3b5237$exports = {};
2318
+
2319
+
2320
+ var $6740b53b975d3884$exports = {};
2321
+
2322
+
2323
+ var $6cfe0c91f2a90e78$exports = {};
2324
+
2325
+
2326
+
2327
+
2328
+
1361
2329
 
2330
+ $parcel$exportWildcard(module.exports, $73c61fb8fd3b5237$exports);
2331
+ $parcel$exportWildcard(module.exports, $6740b53b975d3884$exports);
2332
+ $parcel$exportWildcard(module.exports, $6cfe0c91f2a90e78$exports);
2333
+ $parcel$exportWildcard(module.exports, $9b37fe5960a1a3c6$exports);
2334
+ $parcel$exportWildcard(module.exports, $5c74fef433be2b0a$exports);
2335
+ $parcel$exportWildcard(module.exports, $ce2da9e8a36b0fcd$exports);
2336
+ $parcel$exportWildcard(module.exports, $2492d77b1ec82005$exports);
1362
2337
 
1363
2338
 
1364
2339
  //# sourceMappingURL=index.js.map