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
@@ -0,0 +1,20 @@
1
+ import { initialState } from "./initial";
2
+ /* Reducer */
3
+ export function reducer(state = initialState().nodes.drag, action) {
4
+ switch (action.type) {
5
+ case "DND_DRAG_START":
6
+ return Object.assign(Object.assign({}, state), { id: action.id, selectedIds: action.dragIds });
7
+ case "DND_DRAG_END":
8
+ return Object.assign(Object.assign({}, state), { id: null, destinationParentId: null, destinationIndex: null, selectedIds: [] });
9
+ case "DND_HOVERING":
10
+ if (action.parentId !== state.destinationParentId ||
11
+ action.index != state.destinationIndex) {
12
+ return Object.assign(Object.assign({}, state), { destinationParentId: action.parentId, destinationIndex: action.index });
13
+ }
14
+ else {
15
+ return state;
16
+ }
17
+ default:
18
+ return state;
19
+ }
20
+ }
@@ -0,0 +1,8 @@
1
+ export type EditState = {
2
+ id: string | null;
3
+ };
4
+ export declare function edit(id: string | null): {
5
+ type: "EDIT";
6
+ id: string | null;
7
+ };
8
+ export declare function reducer(state: EditState | undefined, action: ReturnType<typeof edit>): EditState;
@@ -0,0 +1,13 @@
1
+ /* Actions */
2
+ export function edit(id) {
3
+ return { type: "EDIT", id };
4
+ }
5
+ /* Reducer */
6
+ export function reducer(state = { id: null }, action) {
7
+ if (action.type === "EDIT") {
8
+ return Object.assign(Object.assign({}, state), { id: action.id });
9
+ }
10
+ else {
11
+ return state;
12
+ }
13
+ }
@@ -0,0 +1,12 @@
1
+ export type FocusState = {
2
+ id: string | null;
3
+ treeFocused: boolean;
4
+ };
5
+ export declare function focus(id: string | null): {
6
+ type: "FOCUS";
7
+ id: string | null;
8
+ };
9
+ export declare function treeBlur(): {
10
+ readonly type: "TREE_BLUR";
11
+ };
12
+ export declare function reducer(state: FocusState | undefined, action: ReturnType<typeof focus> | ReturnType<typeof treeBlur>): FocusState;
@@ -0,0 +1,20 @@
1
+ /* Types */
2
+ /* Actions */
3
+ export function focus(id) {
4
+ return { type: "FOCUS", id };
5
+ }
6
+ export function treeBlur() {
7
+ return { type: "TREE_BLUR" };
8
+ }
9
+ /* Reducer */
10
+ export function reducer(state = { id: null, treeFocused: false }, action) {
11
+ if (action.type === "FOCUS") {
12
+ return Object.assign(Object.assign({}, state), { id: action.id, treeFocused: true });
13
+ }
14
+ else if (action.type === "TREE_BLUR") {
15
+ return Object.assign(Object.assign({}, state), { treeFocused: false });
16
+ }
17
+ else {
18
+ return state;
19
+ }
20
+ }
@@ -0,0 +1,3 @@
1
+ import { TreeProps } from "../types/tree-props";
2
+ import { RootState } from "./root-reducer";
3
+ export declare const initialState: (props?: TreeProps<any>) => RootState;
@@ -0,0 +1,25 @@
1
+ export const initialState = (props) => {
2
+ var _a;
3
+ return ({
4
+ nodes: {
5
+ // Changes together
6
+ open: { filtered: {}, unfiltered: (_a = props === null || props === void 0 ? void 0 : props.initialOpenState) !== null && _a !== void 0 ? _a : {} },
7
+ focus: { id: null, treeFocused: false },
8
+ edit: { id: null },
9
+ drag: {
10
+ id: null,
11
+ selectedIds: [],
12
+ destinationParentId: null,
13
+ destinationIndex: null,
14
+ },
15
+ selection: { ids: new Set(), anchor: null, mostRecent: null },
16
+ },
17
+ dnd: {
18
+ cursor: { type: "none" },
19
+ dragId: null,
20
+ dragIds: [],
21
+ parentId: null,
22
+ index: -1,
23
+ },
24
+ });
25
+ };
@@ -0,0 +1,30 @@
1
+ import { ActionTypes } from "../types/utils";
2
+ export type OpenMap = {
3
+ [id: string]: boolean;
4
+ };
5
+ export type OpenSlice = {
6
+ unfiltered: OpenMap;
7
+ filtered: OpenMap;
8
+ };
9
+ export declare const actions: {
10
+ open(id: string, filtered: boolean): {
11
+ type: "VISIBILITY_OPEN";
12
+ id: string;
13
+ filtered: boolean;
14
+ };
15
+ close(id: string, filtered: boolean): {
16
+ type: "VISIBILITY_CLOSE";
17
+ id: string;
18
+ filtered: boolean;
19
+ };
20
+ toggle(id: string, filtered: boolean): {
21
+ type: "VISIBILITY_TOGGLE";
22
+ id: string;
23
+ filtered: boolean;
24
+ };
25
+ clear(filtered: boolean): {
26
+ type: "VISIBILITY_CLEAR";
27
+ filtered: boolean;
28
+ };
29
+ };
30
+ export declare function reducer(state: OpenSlice | undefined, action: ActionTypes<typeof actions>): OpenSlice;
@@ -0,0 +1,44 @@
1
+ /* Actions */
2
+ export const actions = {
3
+ open(id, filtered) {
4
+ return { type: "VISIBILITY_OPEN", id, filtered };
5
+ },
6
+ close(id, filtered) {
7
+ return { type: "VISIBILITY_CLOSE", id, filtered };
8
+ },
9
+ toggle(id, filtered) {
10
+ return { type: "VISIBILITY_TOGGLE", id, filtered };
11
+ },
12
+ clear(filtered) {
13
+ return { type: "VISIBILITY_CLEAR", filtered };
14
+ },
15
+ };
16
+ /* Reducer */
17
+ function openMapReducer(state = {}, action) {
18
+ if (action.type === "VISIBILITY_OPEN") {
19
+ return Object.assign(Object.assign({}, state), { [action.id]: true });
20
+ }
21
+ else if (action.type === "VISIBILITY_CLOSE") {
22
+ return Object.assign(Object.assign({}, state), { [action.id]: false });
23
+ }
24
+ else if (action.type === "VISIBILITY_TOGGLE") {
25
+ const prev = state[action.id];
26
+ return Object.assign(Object.assign({}, state), { [action.id]: !prev });
27
+ }
28
+ else if (action.type === "VISIBILITY_CLEAR") {
29
+ return {};
30
+ }
31
+ else {
32
+ return state;
33
+ }
34
+ }
35
+ export function reducer(state = { filtered: {}, unfiltered: {} }, action) {
36
+ if (!action.type.startsWith("VISIBILITY"))
37
+ return state;
38
+ if (action.filtered) {
39
+ return Object.assign(Object.assign({}, state), { filtered: openMapReducer(state.filtered, action) });
40
+ }
41
+ else {
42
+ return Object.assign(Object.assign({}, state), { unfiltered: openMapReducer(state.unfiltered, action) });
43
+ }
44
+ }
@@ -0,0 +1,96 @@
1
+ import { ActionFromReducer } from "redux";
2
+ export declare const rootReducer: import("redux").Reducer<{
3
+ nodes: {
4
+ focus: import("./focus-slice").FocusState;
5
+ edit: import("./edit-slice").EditState;
6
+ open: import("./open-slice").OpenSlice;
7
+ selection: import("./selection-slice").SelectionState;
8
+ drag: import("./drag-slice").DragSlice;
9
+ };
10
+ dnd: import("./dnd-slice").DndState;
11
+ }, {
12
+ type: "FOCUS";
13
+ id: string | null;
14
+ } | {
15
+ readonly type: "TREE_BLUR";
16
+ } | {
17
+ type: "EDIT";
18
+ id: string | null;
19
+ } | import("../types/utils").ActionTypes<{
20
+ open(id: string, filtered: boolean): {
21
+ type: "VISIBILITY_OPEN";
22
+ id: string;
23
+ filtered: boolean;
24
+ };
25
+ close(id: string, filtered: boolean): {
26
+ type: "VISIBILITY_CLOSE";
27
+ id: string;
28
+ filtered: boolean;
29
+ };
30
+ toggle(id: string, filtered: boolean): {
31
+ type: "VISIBILITY_TOGGLE";
32
+ id: string;
33
+ filtered: boolean;
34
+ };
35
+ clear(filtered: boolean): {
36
+ type: "VISIBILITY_CLEAR";
37
+ filtered: boolean;
38
+ };
39
+ }> | import("../types/utils").ActionTypes<{
40
+ clear: () => {
41
+ type: "SELECTION_CLEAR";
42
+ };
43
+ only: (id: string | import("../types/utils").IdObj) => {
44
+ type: "SELECTION_ONLY";
45
+ id: string;
46
+ };
47
+ add: (id: string | import("../types/utils").IdObj | string[] | import("../types/utils").IdObj[]) => {
48
+ type: "SELECTION_ADD";
49
+ ids: string[];
50
+ };
51
+ remove: (id: string | import("../types/utils").IdObj | string[] | import("../types/utils").IdObj[]) => {
52
+ type: "SELECTION_REMOVE";
53
+ ids: string[];
54
+ };
55
+ set: (args: {
56
+ ids: Set<string>;
57
+ anchor: string | null;
58
+ mostRecent: string | null;
59
+ }) => {
60
+ ids: Set<string>;
61
+ anchor: string | null;
62
+ mostRecent: string | null;
63
+ type: "SELECTION_SET";
64
+ };
65
+ mostRecent: (id: string | import("../types/utils").IdObj | null) => {
66
+ type: "SELECTION_MOST_RECENT";
67
+ id: string | null;
68
+ };
69
+ anchor: (id: string | import("../types/utils").IdObj | null) => {
70
+ type: "SELECTION_ANCHOR";
71
+ id: string | null;
72
+ };
73
+ }> | import("../types/utils").ActionTypes<{
74
+ cursor(cursor: import("../dnd/compute-drop").Cursor): {
75
+ type: "DND_CURSOR";
76
+ cursor: import("../dnd/compute-drop").Cursor;
77
+ };
78
+ dragStart(id: string, dragIds: string[]): {
79
+ type: "DND_DRAG_START";
80
+ id: string;
81
+ dragIds: string[];
82
+ };
83
+ dragEnd(): {
84
+ type: "DND_DRAG_END";
85
+ };
86
+ hovering(parentId: string | null, index: number | null): {
87
+ type: "DND_HOVERING";
88
+ parentId: string | null;
89
+ index: number | null;
90
+ };
91
+ }>, Partial<{
92
+ nodes: never;
93
+ dnd: never;
94
+ }>>;
95
+ export type RootState = ReturnType<typeof rootReducer>;
96
+ export type Actions = ActionFromReducer<typeof rootReducer>;
@@ -0,0 +1,17 @@
1
+ import { combineReducers } from "redux";
2
+ import { reducer as focus } from "./focus-slice";
3
+ import { reducer as edit } from "./edit-slice";
4
+ import { reducer as dnd } from "./dnd-slice";
5
+ import { reducer as selection } from "./selection-slice";
6
+ import { reducer as open } from "./open-slice";
7
+ import { reducer as drag } from "./drag-slice";
8
+ export const rootReducer = combineReducers({
9
+ nodes: combineReducers({
10
+ focus,
11
+ edit,
12
+ open,
13
+ selection,
14
+ drag,
15
+ }),
16
+ dnd,
17
+ });
@@ -0,0 +1,42 @@
1
+ import { ActionTypes, IdObj } from "../types/utils";
2
+ export type SelectionState = {
3
+ ids: Set<string>;
4
+ anchor: string | null;
5
+ mostRecent: string | null;
6
+ };
7
+ export declare const actions: {
8
+ clear: () => {
9
+ type: "SELECTION_CLEAR";
10
+ };
11
+ only: (id: string | IdObj) => {
12
+ type: "SELECTION_ONLY";
13
+ id: string;
14
+ };
15
+ add: (id: string | string[] | IdObj | IdObj[]) => {
16
+ type: "SELECTION_ADD";
17
+ ids: string[];
18
+ };
19
+ remove: (id: string | string[] | IdObj | IdObj[]) => {
20
+ type: "SELECTION_REMOVE";
21
+ ids: string[];
22
+ };
23
+ set: (args: {
24
+ ids: Set<string>;
25
+ anchor: string | null;
26
+ mostRecent: string | null;
27
+ }) => {
28
+ ids: Set<string>;
29
+ anchor: string | null;
30
+ mostRecent: string | null;
31
+ type: "SELECTION_SET";
32
+ };
33
+ mostRecent: (id: string | null | IdObj) => {
34
+ type: "SELECTION_MOST_RECENT";
35
+ id: string | null;
36
+ };
37
+ anchor: (id: string | null | IdObj) => {
38
+ type: "SELECTION_ANCHOR";
39
+ id: string | null;
40
+ };
41
+ };
42
+ export declare function reducer(state: SelectionState | undefined, action: ActionTypes<typeof actions>): SelectionState;
@@ -0,0 +1,55 @@
1
+ import { identify } from "../utils";
2
+ import { initialState } from "./initial";
3
+ /* Actions */
4
+ export const actions = {
5
+ clear: () => ({ type: "SELECTION_CLEAR" }),
6
+ only: (id) => ({
7
+ type: "SELECTION_ONLY",
8
+ id: identify(id),
9
+ }),
10
+ add: (id) => ({
11
+ type: "SELECTION_ADD",
12
+ ids: (Array.isArray(id) ? id : [id]).map(identify),
13
+ }),
14
+ remove: (id) => ({
15
+ type: "SELECTION_REMOVE",
16
+ ids: (Array.isArray(id) ? id : [id]).map(identify),
17
+ }),
18
+ set: (args) => (Object.assign({ type: "SELECTION_SET" }, args)),
19
+ mostRecent: (id) => ({
20
+ type: "SELECTION_MOST_RECENT",
21
+ id: id === null ? null : identify(id),
22
+ }),
23
+ anchor: (id) => ({
24
+ type: "SELECTION_ANCHOR",
25
+ id: id === null ? null : identify(id),
26
+ }),
27
+ };
28
+ /* Reducer */
29
+ export function reducer(state = initialState()["nodes"]["selection"], action) {
30
+ const ids = state.ids;
31
+ switch (action.type) {
32
+ case "SELECTION_CLEAR":
33
+ return Object.assign(Object.assign({}, state), { ids: new Set() });
34
+ case "SELECTION_ONLY":
35
+ return Object.assign(Object.assign({}, state), { ids: new Set([action.id]) });
36
+ case "SELECTION_ADD":
37
+ if (action.ids.length === 0)
38
+ return state;
39
+ action.ids.forEach((id) => ids.add(id));
40
+ return Object.assign(Object.assign({}, state), { ids: new Set(ids) });
41
+ case "SELECTION_REMOVE":
42
+ if (action.ids.length === 0)
43
+ return state;
44
+ action.ids.forEach((id) => ids.delete(id));
45
+ return Object.assign(Object.assign({}, state), { ids: new Set(ids) });
46
+ case "SELECTION_SET":
47
+ return Object.assign(Object.assign({}, state), { ids: action.ids, mostRecent: action.mostRecent, anchor: action.anchor });
48
+ case "SELECTION_MOST_RECENT":
49
+ return Object.assign(Object.assign({}, state), { mostRecent: action.id });
50
+ case "SELECTION_ANCHOR":
51
+ return Object.assign(Object.assign({}, state), { anchor: action.id });
52
+ default:
53
+ return state;
54
+ }
55
+ }
@@ -0,0 +1,8 @@
1
+ export type CursorLocation = {
2
+ index: number | null;
3
+ level: number | null;
4
+ parentId: string | null;
5
+ };
6
+ export type DragItem = {
7
+ id: string;
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ import { NodeApi } from "../interfaces/node-api";
2
+ import { IdObj } from "./utils";
3
+ export type CreateHandler<T> = (args: {
4
+ parentId: string | null;
5
+ parentNode: NodeApi<T> | null;
6
+ index: number;
7
+ type: "internal" | "leaf";
8
+ }) => (IdObj | null) | Promise<IdObj | null>;
9
+ export type MoveHandler<T> = (args: {
10
+ dragIds: string[];
11
+ dragNodes: NodeApi<T>[];
12
+ parentId: string | null;
13
+ parentNode: NodeApi<T> | null;
14
+ index: number;
15
+ }) => void | Promise<void>;
16
+ export type RenameHandler<T> = (args: {
17
+ id: string;
18
+ name: string;
19
+ node: NodeApi<T>;
20
+ }) => void | Promise<void>;
21
+ export type DeleteHandler<T> = (args: {
22
+ ids: string[];
23
+ nodes: NodeApi<T>[];
24
+ }) => void | Promise<void>;
25
+ export type EditResult = {
26
+ cancelled: true;
27
+ } | {
28
+ cancelled: false;
29
+ value: string;
30
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import { CSSProperties, HTMLAttributes, ReactElement } from "react";
2
+ import { NodeApi } from "../interfaces/node-api";
3
+ import { TreeApi } from "../interfaces/tree-api";
4
+ import { XYCoord } from "react-dnd";
5
+ export type NodeRendererProps<T> = {
6
+ style: CSSProperties;
7
+ node: NodeApi<T>;
8
+ tree: TreeApi<T>;
9
+ dragHandle?: (el: HTMLDivElement | null) => void;
10
+ preview?: boolean;
11
+ };
12
+ export type RowRendererProps<T> = {
13
+ node: NodeApi<T>;
14
+ innerRef: (el: HTMLDivElement | null) => void;
15
+ attrs: HTMLAttributes<any>;
16
+ children: ReactElement;
17
+ };
18
+ export type DragPreviewProps = {
19
+ offset: XYCoord | null;
20
+ mouse: XYCoord | null;
21
+ id: string | null;
22
+ dragIds: string[];
23
+ isDragging: boolean;
24
+ };
25
+ export type CursorProps = {
26
+ top: number;
27
+ left: number;
28
+ indent: number;
29
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { NodeApi } from "../interfaces/node-api";
2
+ export type NodeState = typeof NodeApi.prototype["state"];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,56 @@
1
+ import { BoolFunc } from "./utils";
2
+ import * as handlers from "./handlers";
3
+ import * as renderers from "./renderers";
4
+ import { ElementType, MouseEventHandler } from "react";
5
+ import { ListOnScrollProps } from "react-window";
6
+ import { NodeApi } from "../interfaces/node-api";
7
+ import { OpenMap } from "../state/open-slice";
8
+ import { useDragDropManager } from "react-dnd";
9
+ export interface TreeProps<T> {
10
+ data?: readonly T[];
11
+ initialData?: readonly T[];
12
+ onCreate?: handlers.CreateHandler<T>;
13
+ onMove?: handlers.MoveHandler<T>;
14
+ onRename?: handlers.RenameHandler<T>;
15
+ onDelete?: handlers.DeleteHandler<T>;
16
+ children?: ElementType<renderers.NodeRendererProps<T>>;
17
+ renderRow?: ElementType<renderers.RowRendererProps<T>>;
18
+ renderDragPreview?: ElementType<renderers.DragPreviewProps>;
19
+ renderCursor?: ElementType<renderers.CursorProps>;
20
+ renderContainer?: ElementType<{}>;
21
+ rowHeight?: number;
22
+ overscanCount?: number;
23
+ width?: number | string;
24
+ height?: number;
25
+ indent?: number;
26
+ paddingTop?: number;
27
+ paddingBottom?: number;
28
+ padding?: number;
29
+ childrenAccessor?: string | ((d: T) => T[] | null);
30
+ idAccessor?: string | ((d: T) => string);
31
+ openByDefault?: boolean;
32
+ selectionFollowsFocus?: boolean;
33
+ disableMultiSelection?: boolean;
34
+ disableEdit?: string | boolean | BoolFunc<T>;
35
+ disableDrag?: string | boolean | BoolFunc<T>;
36
+ disableDrop?: string | boolean | ((args: {
37
+ parentNode: NodeApi<T>;
38
+ dragNodes: NodeApi<T>[];
39
+ index: number;
40
+ }) => boolean);
41
+ onActivate?: (node: NodeApi<T>) => void;
42
+ onSelect?: (nodes: NodeApi<T>[]) => void;
43
+ onScroll?: (props: ListOnScrollProps) => void;
44
+ onToggle?: (id: string) => void;
45
+ onFocus?: (node: NodeApi<T>) => void;
46
+ selection?: string;
47
+ initialOpenState?: OpenMap;
48
+ searchTerm?: string;
49
+ searchMatch?: (node: NodeApi<T>, searchTerm: string) => boolean;
50
+ className?: string | undefined;
51
+ rowClassName?: string | undefined;
52
+ dndRootElement?: globalThis.Node | null;
53
+ onClick?: MouseEventHandler;
54
+ onContextMenu?: MouseEventHandler;
55
+ dndManager?: ReturnType<typeof useDragDropManager>;
56
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { AnyAction } from "redux";
2
+ import { NodeApi } from "../interfaces/node-api";
3
+ export interface IdObj {
4
+ id: string;
5
+ }
6
+ export type Identity = string | IdObj | null;
7
+ export type BoolFunc<T> = (data: T) => boolean;
8
+ export type ActionTypes<Actions extends {
9
+ [name: string]: (...args: any[]) => AnyAction;
10
+ }> = ReturnType<Actions[keyof Actions]>;
11
+ export type SelectOptions = {
12
+ multi?: boolean;
13
+ contiguous?: boolean;
14
+ };
15
+ export type NodesById<T> = {
16
+ [id: string]: NodeApi<T>;
17
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import { NodeApi } from "./interfaces/node-api";
2
+ import { TreeApi } from "./interfaces/tree-api";
3
+ import { IdObj } from "./types/utils";
4
+ export declare function bound(n: number, min: number, max: number): number;
5
+ export declare function isItem(node: NodeApi<any> | null): boolean | null;
6
+ export declare function isClosed(node: NodeApi<any> | null): boolean | null;
7
+ /**
8
+ * Is first param a descendant of the second param
9
+ */
10
+ export declare const isDescendant: (a: NodeApi<any>, b: NodeApi<any>) => boolean;
11
+ export declare const indexOf: (node: NodeApi<any>) => number;
12
+ export declare function noop(): void;
13
+ export declare function dfs(node: NodeApi<any>, id: string): NodeApi<any> | null;
14
+ export declare function walk(node: NodeApi<any>, fn: (node: NodeApi<any>) => void): void;
15
+ export declare function focusNextElement(target: HTMLElement): void;
16
+ export declare function focusPrevElement(target: HTMLElement): void;
17
+ export declare function access<T = boolean>(obj: any, accessor: string | boolean | Function): T;
18
+ export declare function identifyNull(obj: string | IdObj | null): string | null;
19
+ export declare function identify(obj: string | IdObj): string;
20
+ export declare function mergeRefs(...refs: any): (instance: any) => void;
21
+ export declare function safeRun<T extends (...args: any[]) => any>(fn: T | undefined, ...args: Parameters<T>): any;
22
+ export declare function waitFor(fn: () => boolean): Promise<void>;
23
+ export declare function getInsertIndex(tree: TreeApi<any>): number;
24
+ export declare function getInsertParentId(tree: TreeApi<any>): string | null;