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