react-arborist 1.2.0 → 2.0.0-rc

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