react-native-tree-multi-select 3.0.0-beta.1 → 3.0.0-beta.3
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.
- package/README.md +1 -1
- package/lib/module/components/DragOverlay.js +3 -0
- package/lib/module/components/DragOverlay.js.map +1 -1
- package/lib/module/components/NodeList.js +61 -25
- package/lib/module/components/NodeList.js.map +1 -1
- package/lib/module/helpers/toggleCheckbox.helper.js +1 -1
- package/lib/module/hooks/useDragDrop.js +214 -30
- package/lib/module/hooks/useDragDrop.js.map +1 -1
- package/lib/module/store/treeView.store.js +6 -3
- package/lib/module/store/treeView.store.js.map +1 -1
- package/lib/typescript/src/components/DragOverlay.d.ts +1 -0
- package/lib/typescript/src/components/DragOverlay.d.ts.map +1 -1
- package/lib/typescript/src/components/NodeList.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useDragDrop.d.ts +5 -0
- package/lib/typescript/src/hooks/useDragDrop.d.ts.map +1 -1
- package/lib/typescript/src/store/treeView.store.d.ts +2 -1
- package/lib/typescript/src/store/treeView.store.d.ts.map +1 -1
- package/lib/typescript/src/types/dragDrop.types.d.ts +9 -0
- package/lib/typescript/src/types/dragDrop.types.d.ts.map +1 -1
- package/lib/typescript/src/types/treeView.types.d.ts +94 -4
- package/lib/typescript/src/types/treeView.types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/DragOverlay.tsx +3 -1
- package/src/components/NodeList.tsx +62 -29
- package/src/helpers/toggleCheckbox.helper.ts +1 -1
- package/src/hooks/useDragDrop.ts +237 -31
- package/src/store/treeView.store.ts +6 -2
- package/src/types/dragDrop.types.ts +9 -0
- package/src/types/treeView.types.ts +94 -7
|
@@ -14,89 +14,138 @@ import type {
|
|
|
14
14
|
} from "@futurejj/react-native-checkbox";
|
|
15
15
|
import type { DragEndEvent, DropPosition } from "./dragDrop.types";
|
|
16
16
|
|
|
17
|
+
/** The tri-state value of a checkbox: checked, unchecked, or indeterminate */
|
|
17
18
|
export type CheckboxValueType = boolean | "indeterminate";
|
|
18
19
|
|
|
20
|
+
/** Props passed to a custom expand/collapse icon component */
|
|
19
21
|
export interface ExpandIconProps {
|
|
22
|
+
/** Whether the node is currently expanded */
|
|
20
23
|
isExpanded: boolean;
|
|
21
24
|
}
|
|
22
25
|
|
|
26
|
+
/** A single node in the tree data structure */
|
|
23
27
|
export interface TreeNode<ID = string> {
|
|
28
|
+
/** Unique identifier for this node */
|
|
24
29
|
id: ID;
|
|
30
|
+
/** Display name for this node */
|
|
25
31
|
name: string;
|
|
32
|
+
/** Child nodes (omit or empty array for leaf nodes) */
|
|
26
33
|
children?: TreeNode<ID>[];
|
|
34
|
+
/** Additional custom data fields */
|
|
27
35
|
[key: string]: any;
|
|
28
36
|
}
|
|
29
37
|
|
|
38
|
+
/** Internal flattened representation of a tree node with its nesting level */
|
|
30
39
|
export interface __FlattenedTreeNode__<ID = string> extends TreeNode<ID> {
|
|
40
|
+
/** Nesting depth of this node (0 = root level) */
|
|
31
41
|
level?: number;
|
|
32
42
|
}
|
|
33
43
|
|
|
34
|
-
|
|
44
|
+
/** FlashList props available for customization (excludes `data` and `renderItem`) */
|
|
35
45
|
export type TreeFlatListProps<ItemT = any> = Omit<
|
|
36
46
|
FlashListProps<ItemT>,
|
|
37
47
|
"data"
|
|
38
48
|
| "renderItem"
|
|
39
49
|
>;
|
|
40
50
|
|
|
51
|
+
/** Props passed to a custom node row component */
|
|
41
52
|
export interface NodeRowProps<ID = string> {
|
|
53
|
+
/** The tree node to render */
|
|
42
54
|
node: TreeNode<ID>;
|
|
55
|
+
/** Nesting depth of this node (0 = root level) */
|
|
43
56
|
level: number;
|
|
44
57
|
|
|
58
|
+
/** Current checkbox state of this node */
|
|
45
59
|
checkedValue: CheckboxValueType;
|
|
60
|
+
/** Whether this node's children are currently visible */
|
|
46
61
|
isExpanded: boolean;
|
|
47
62
|
|
|
63
|
+
/** Callback to toggle this node's checked state */
|
|
48
64
|
onCheck: () => void;
|
|
65
|
+
/** Callback to toggle this node's expanded/collapsed state */
|
|
49
66
|
onExpand: () => void;
|
|
50
67
|
|
|
68
|
+
/** Whether this node is an invalid drop target during a drag operation */
|
|
51
69
|
isDragTarget?: boolean;
|
|
70
|
+
/** Whether a drag operation is currently in progress */
|
|
52
71
|
isDragging?: boolean;
|
|
72
|
+
/** Whether this node is the one being dragged */
|
|
53
73
|
isDraggedNode?: boolean;
|
|
54
74
|
}
|
|
55
75
|
|
|
76
|
+
/** Customization options for tree item appearance and behavior */
|
|
56
77
|
export interface TreeItemCustomizations<ID> {
|
|
78
|
+
/** Style props for the built-in checkbox view */
|
|
57
79
|
checkBoxViewStyleProps?: BuiltInCheckBoxViewStyleProps;
|
|
58
80
|
|
|
81
|
+
/** Pixels of indentation per nesting level. Default: 15 */
|
|
59
82
|
indentationMultiplier?: number;
|
|
60
83
|
|
|
84
|
+
/** Custom checkbox component replacing the built-in checkbox */
|
|
61
85
|
CheckboxComponent?: React.ComponentType<CheckBoxViewProps>;
|
|
86
|
+
/** Custom expand/collapse icon component */
|
|
62
87
|
ExpandCollapseIconComponent?: React.ComponentType<ExpandIconProps>;
|
|
88
|
+
/** Custom touchable component wrapping the expand/collapse icon */
|
|
63
89
|
ExpandCollapseTouchableComponent?: React.ComponentType<TouchableOpacityProps>;
|
|
64
90
|
|
|
91
|
+
/** Fully custom node row component replacing the entire built-in row */
|
|
65
92
|
CustomNodeRowComponent?: React.ComponentType<NodeRowProps<ID>>;
|
|
66
93
|
}
|
|
67
94
|
|
|
95
|
+
/** Internal props for a single node in the list (extends TreeItemCustomizations) */
|
|
68
96
|
export interface NodeProps<ID> extends TreeItemCustomizations<ID> {
|
|
97
|
+
/** The flattened tree node data */
|
|
69
98
|
node: __FlattenedTreeNode__<ID>;
|
|
99
|
+
/** Nesting depth of this node */
|
|
70
100
|
level: number;
|
|
101
|
+
/** Internal store identifier */
|
|
71
102
|
storeId: string;
|
|
72
103
|
|
|
104
|
+
/** Index of this node in the flattened list */
|
|
73
105
|
nodeIndex?: number;
|
|
106
|
+
/** Whether drag-and-drop is enabled */
|
|
74
107
|
dragEnabled?: boolean;
|
|
108
|
+
/** Whether a drag operation is currently in progress */
|
|
75
109
|
isDragging?: boolean;
|
|
110
|
+
/** Callback when a touch starts on this node (used for drag initiation) */
|
|
76
111
|
onNodeTouchStart?: (
|
|
77
112
|
nodeId: ID,
|
|
78
113
|
pageY: number,
|
|
79
114
|
locationY: number,
|
|
80
115
|
nodeIndex: number
|
|
81
116
|
) => void;
|
|
117
|
+
/** Callback when a touch ends on this node */
|
|
82
118
|
onNodeTouchEnd?: () => void;
|
|
119
|
+
/** Long press duration in ms to start drag */
|
|
83
120
|
longPressDuration?: number;
|
|
121
|
+
/** Callback reporting this node's measured height */
|
|
84
122
|
onItemLayout?: (height: number) => void;
|
|
123
|
+
/** Customizations for drag-and-drop visuals */
|
|
85
124
|
dragDropCustomizations?: DragDropCustomizations<ID>;
|
|
86
125
|
}
|
|
87
126
|
|
|
127
|
+
/** Props for the NodeList component that renders the flattened tree */
|
|
88
128
|
export interface NodeListProps<ID> extends TreeItemCustomizations<ID> {
|
|
129
|
+
/** Additional props passed to the underlying FlashList */
|
|
89
130
|
treeFlashListProps?: TreeFlatListProps;
|
|
90
131
|
|
|
132
|
+
/** Ref for programmatic scroll-to-node functionality */
|
|
91
133
|
scrollToNodeHandlerRef: React.RefObject<ScrollToNodeHandlerRef<ID>>;
|
|
134
|
+
/** Node ID to scroll to on initial render */
|
|
92
135
|
initialScrollNodeID?: ID;
|
|
93
136
|
|
|
137
|
+
/** Internal store identifier */
|
|
94
138
|
storeId: string;
|
|
95
139
|
|
|
140
|
+
/** Enable drag-and-drop reordering */
|
|
96
141
|
dragEnabled?: boolean;
|
|
142
|
+
/** Callback fired after a node is dropped at a new position */
|
|
97
143
|
onDragEnd?: (event: DragEndEvent<ID>) => void;
|
|
144
|
+
/** Long press duration in ms to start drag. Default: 400 */
|
|
98
145
|
longPressDuration?: number;
|
|
146
|
+
/** Distance from edge (px) to trigger auto-scroll during drag. Default: 60 */
|
|
99
147
|
autoScrollThreshold?: number;
|
|
148
|
+
/** Speed multiplier for auto-scroll during drag. Default: 1.0 */
|
|
100
149
|
autoScrollSpeed?: number;
|
|
101
150
|
/** Offset of the dragged overlay from the finger, in item-height units. Default: -1 (one item above finger) */
|
|
102
151
|
dragOverlayOffset?: number;
|
|
@@ -106,18 +155,25 @@ export interface NodeListProps<ID> extends TreeItemCustomizations<ID> {
|
|
|
106
155
|
dragDropCustomizations?: DragDropCustomizations<ID>;
|
|
107
156
|
}
|
|
108
157
|
|
|
158
|
+
/** Props for the TreeView component */
|
|
109
159
|
export interface TreeViewProps<ID = string> extends Omit<
|
|
110
160
|
NodeListProps<ID>, "storeId" | "scrollToNodeHandlerRef"
|
|
111
161
|
> {
|
|
162
|
+
/** The tree data to render */
|
|
112
163
|
data: TreeNode<ID>[];
|
|
113
164
|
|
|
165
|
+
/** Callback fired when checked nodes change. Receives checked and indeterminate node IDs. */
|
|
114
166
|
onCheck?: (checkedIds: ID[], indeterminateIds: ID[]) => void;
|
|
167
|
+
/** Callback fired when expanded nodes change. Receives all currently expanded node IDs. */
|
|
115
168
|
onExpand?: (expandedIds: ID[]) => void;
|
|
116
169
|
|
|
170
|
+
/** Node IDs that should be checked on initial render */
|
|
117
171
|
preselectedIds?: ID[];
|
|
118
172
|
|
|
173
|
+
/** Node IDs that should be expanded on initial render */
|
|
119
174
|
preExpandedIds?: ID[];
|
|
120
175
|
|
|
176
|
+
/** Controls whether checking a node propagates to its children and/or parents */
|
|
121
177
|
selectionPropagation?: SelectionPropagation;
|
|
122
178
|
|
|
123
179
|
/** Enable drag-and-drop reordering */
|
|
@@ -126,9 +182,9 @@ export interface TreeViewProps<ID = string> extends Omit<
|
|
|
126
182
|
onDragEnd?: (event: DragEndEvent<ID>) => void;
|
|
127
183
|
/** Long press duration in ms to start drag. Default: 400 */
|
|
128
184
|
longPressDuration?: number;
|
|
129
|
-
/** Distance from edge (px) to trigger auto-scroll. Default: 60 */
|
|
185
|
+
/** Distance from edge (px) to trigger auto-scroll during drag. Default: 60 */
|
|
130
186
|
autoScrollThreshold?: number;
|
|
131
|
-
/** Speed multiplier for auto-scroll. Default: 1.0 */
|
|
187
|
+
/** Speed multiplier for auto-scroll during drag. Default: 1.0 */
|
|
132
188
|
autoScrollSpeed?: number;
|
|
133
189
|
/** Offset of the dragged overlay from the finger, in item-height units. Default: -1 (one item above finger) */
|
|
134
190
|
dragOverlayOffset?: number;
|
|
@@ -138,53 +194,80 @@ export interface TreeViewProps<ID = string> extends Omit<
|
|
|
138
194
|
|
|
139
195
|
type CheckboxProps = Omit<_CheckboxProps, "onPress" | "status">;
|
|
140
196
|
|
|
197
|
+
/** Props for the checkbox view component */
|
|
141
198
|
export interface CheckBoxViewProps {
|
|
199
|
+
/** Current checkbox state */
|
|
142
200
|
value: CheckboxValueType;
|
|
201
|
+
/** Callback when the checkbox value changes */
|
|
143
202
|
onValueChange: (value: boolean) => void;
|
|
203
|
+
/** Label text displayed next to the checkbox */
|
|
144
204
|
text: string;
|
|
205
|
+
/** Test ID for testing frameworks */
|
|
145
206
|
testID?: string;
|
|
146
207
|
}
|
|
147
208
|
|
|
209
|
+
/** Style props for customizing the built-in checkbox view */
|
|
148
210
|
export interface BuiltInCheckBoxViewStyleProps {
|
|
149
|
-
|
|
211
|
+
/** Style for the outermost container wrapping the checkbox and text */
|
|
150
212
|
outermostParentViewStyle?: StyleProp<ViewStyle>;
|
|
213
|
+
/** Style for the view wrapping the checkbox itself */
|
|
151
214
|
checkboxParentViewStyle?: StyleProp<ViewStyle>;
|
|
215
|
+
/** Style for the touchable area wrapping the label text */
|
|
152
216
|
textTouchableStyle?: StyleProp<ViewStyle>;
|
|
153
217
|
|
|
154
|
-
|
|
218
|
+
/** Additional props passed to the underlying Checkbox component */
|
|
155
219
|
checkboxProps?: CheckboxProps;
|
|
220
|
+
/** Props passed to the label Text component */
|
|
156
221
|
textProps?: TextProps;
|
|
157
222
|
}
|
|
158
223
|
|
|
224
|
+
/** Combined props for the built-in checkbox view (CheckBoxViewProps + style props) */
|
|
159
225
|
export type BuiltInCheckBoxViewProps =
|
|
160
226
|
CheckBoxViewProps
|
|
161
227
|
& BuiltInCheckBoxViewStyleProps;
|
|
162
228
|
|
|
229
|
+
/** Ref handle exposed by the TreeView component for imperative operations */
|
|
163
230
|
export interface TreeViewRef<ID = string> {
|
|
231
|
+
/** Select (check) all nodes in the tree */
|
|
164
232
|
selectAll: () => void;
|
|
233
|
+
/** Unselect (uncheck) all nodes in the tree */
|
|
165
234
|
unselectAll: () => void;
|
|
166
235
|
|
|
236
|
+
/** Select all nodes that match the current search filter */
|
|
167
237
|
selectAllFiltered: () => void;
|
|
238
|
+
/** Unselect all nodes that match the current search filter */
|
|
168
239
|
unselectAllFiltered: () => void;
|
|
169
240
|
|
|
241
|
+
/** Expand all nodes in the tree */
|
|
170
242
|
expandAll: () => void;
|
|
243
|
+
/** Collapse all nodes in the tree */
|
|
171
244
|
collapseAll: () => void;
|
|
172
245
|
|
|
246
|
+
/** Expand specific nodes by their IDs */
|
|
173
247
|
expandNodes: (ids: ID[]) => void;
|
|
248
|
+
/** Collapse specific nodes by their IDs */
|
|
174
249
|
collapseNodes: (ids: ID[]) => void;
|
|
175
250
|
|
|
251
|
+
/** Select (check) specific nodes by their IDs */
|
|
176
252
|
selectNodes: (ids: ID[]) => void;
|
|
253
|
+
/** Unselect (uncheck) specific nodes by their IDs */
|
|
177
254
|
unselectNodes: (ids: ID[]) => void;
|
|
178
255
|
|
|
256
|
+
/** Set the search text and optionally specify which node fields to search */
|
|
179
257
|
setSearchText: (searchText: string, searchKeys?: string[]) => void;
|
|
180
258
|
|
|
259
|
+
/** Programmatically scroll to a specific node by its ID */
|
|
181
260
|
scrollToNodeID: (scrollToNodeParams: ScrollToNodeParams<ID>) => void;
|
|
182
261
|
|
|
262
|
+
/** Get a map of child node IDs to their parent node IDs */
|
|
183
263
|
getChildToParentMap: () => Map<ID, ID>;
|
|
184
264
|
}
|
|
185
265
|
|
|
266
|
+
/** Controls how checkbox selection propagates through the tree hierarchy */
|
|
186
267
|
export interface SelectionPropagation {
|
|
268
|
+
/** Whether checking a parent node automatically checks all its children. Default: true */
|
|
187
269
|
toChildren?: boolean;
|
|
270
|
+
/** Whether checking all children automatically checks their parent. Default: true */
|
|
188
271
|
toParents?: boolean;
|
|
189
272
|
}
|
|
190
273
|
|
|
@@ -194,6 +277,10 @@ export interface SelectionPropagation {
|
|
|
194
277
|
export interface DropIndicatorComponentProps {
|
|
195
278
|
/** Whether the indicator is above, below, or inside the target node */
|
|
196
279
|
position: DropPosition;
|
|
280
|
+
/** The nesting level of the target node (useful for indenting the indicator) */
|
|
281
|
+
level: number;
|
|
282
|
+
/** The indentation multiplier used for each level (pixels per level) */
|
|
283
|
+
indentationMultiplier: number;
|
|
197
284
|
}
|
|
198
285
|
|
|
199
286
|
/** Style props for customizing the built-in drop indicator appearance */
|
|
@@ -234,9 +321,9 @@ export interface DragDropCustomizations<ID = string> {
|
|
|
234
321
|
dropIndicatorStyleProps?: DropIndicatorStyleProps;
|
|
235
322
|
/** Style props for the drag overlay (lifted node ghost) */
|
|
236
323
|
dragOverlayStyleProps?: DragOverlayStyleProps;
|
|
237
|
-
/** Fully custom drop indicator component
|
|
324
|
+
/** Fully custom drop indicator component - replaces the built-in line/highlight */
|
|
238
325
|
CustomDropIndicatorComponent?: React.ComponentType<DropIndicatorComponentProps>;
|
|
239
|
-
/** Fully custom drag overlay component
|
|
326
|
+
/** Fully custom drag overlay component - replaces the built-in ghost node */
|
|
240
327
|
CustomDragOverlayComponent?: React.ComponentType<DragOverlayComponentProps<ID>>;
|
|
241
328
|
}
|
|
242
329
|
|