react-arborist 3.2.0 → 3.3.1-0

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