@addev-be/ui 3.3.0 → 3.3.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/assets/icons/arrow-down-1-9.svg +1 -1
- package/assets/icons/arrow-down-a-z.svg +1 -1
- package/assets/icons/arrow-up-z-a.svg +1 -1
- package/assets/icons/check.svg +1 -1
- package/assets/icons/circle-check.svg +1 -1
- package/assets/icons/down.svg +1 -1
- package/assets/icons/filter-full.svg +1 -1
- package/assets/icons/filter.svg +1 -1
- package/assets/icons/hashtag.svg +1 -1
- package/assets/icons/image-slash.svg +1 -1
- package/assets/icons/left.svg +1 -1
- package/assets/icons/magnifier.svg +1 -1
- package/assets/icons/phone.svg +1 -1
- package/assets/icons/right.svg +1 -1
- package/assets/icons/sort-calendar-ascending.svg +5 -5
- package/assets/icons/spinner-third.svg +1 -1
- package/assets/icons/table-columns.svg +1 -1
- package/assets/icons/table-footer-slash.svg +4 -4
- package/assets/icons/table-footer.svg +3 -3
- package/assets/icons/table.svg +1 -1
- package/assets/icons/up.svg +1 -1
- package/assets/icons/user-tie.svg +1 -1
- package/assets/icons/x-bar.svg +3 -3
- package/dist/components/grid/DataGrid/helpers/columns.js +22 -2
- package/dist/components/grid/DataGrid/types.d.ts +2 -7
- package/dist/components/grid/SqlRequestDataGrid/helpers/columns.js +13 -1
- package/dist/helpers/styled/typography.d.ts +5 -5
- package/dist/helpers/styled/typography.js +5 -5
- package/eslint.config.js +3 -3
- package/package.json +2 -2
- package/src/components/auth/LoginForm.tsx +92 -92
- package/src/components/auth/LoginPage.tsx +32 -32
- package/src/components/auth/PasswordRecoveryForm.tsx +53 -53
- package/src/components/auth/PasswordResetForm.tsx +114 -114
- package/src/components/auth/index.ts +4 -4
- package/src/components/auth/styles.ts +14 -14
- package/src/components/common/Accordion/Accordion.tsx +140 -140
- package/src/components/common/Accordion/index.ts +2 -2
- package/src/components/common/Avatar/index.tsx +54 -54
- package/src/components/common/Avatar/styles.ts +61 -61
- package/src/components/common/Card/index.tsx +17 -17
- package/src/components/common/Card/styles.ts +38 -38
- package/src/components/common/ContextMenu/index.tsx +79 -79
- package/src/components/common/ContextMenu/styles.ts +119 -119
- package/src/components/common/Ellipsis.tsx +33 -33
- package/src/components/common/Label.tsx +93 -93
- package/src/components/common/Message/index.tsx +57 -57
- package/src/components/common/Message/styles.ts +44 -44
- package/src/components/common/PropertiesList/PropertyInput.tsx +173 -173
- package/src/components/common/PropertiesList/index.tsx +48 -48
- package/src/components/common/PropertiesList/types.ts +60 -60
- package/src/components/common/TabsView/TabsList.tsx +49 -49
- package/src/components/common/TabsView/TabsView.tsx +42 -42
- package/src/components/common/TabsView/index.ts +3 -3
- package/src/components/common/TabsView/styles.ts +83 -83
- package/src/components/common/TabsView/types.ts +12 -12
- package/src/components/common/TreeView/TreeContext.tsx +379 -379
- package/src/components/common/TreeView/TreeView.tsx +281 -281
- package/src/components/common/TreeView/index.ts +3 -3
- package/src/components/common/index.ts +10 -10
- package/src/components/forms/AutoTextArea.tsx +48 -48
- package/src/components/forms/BillitIdentifier/index.tsx +78 -78
- package/src/components/forms/BillitIdentifier/styles.tsx +43 -43
- package/src/components/forms/Button.tsx +130 -130
- package/src/components/forms/Form/Checkbox.tsx +12 -12
- package/src/components/forms/Form/CustomSelect.tsx +86 -86
- package/src/components/forms/Form/FormGroup.tsx +33 -33
- package/src/components/forms/Form/Input.tsx +16 -16
- package/src/components/forms/Form/Row.tsx +28 -28
- package/src/components/forms/Form/Select.tsx +99 -99
- package/src/components/forms/Form/TextArea.tsx +17 -17
- package/src/components/forms/Form/index.tsx +48 -48
- package/src/components/forms/Form/styles.ts +148 -148
- package/src/components/forms/IconButton.tsx +61 -61
- package/src/components/forms/IndeterminateCheckbox.tsx +46 -46
- package/src/components/forms/NumberInput.tsx +53 -53
- package/src/components/forms/Select.tsx +34 -34
- package/src/components/forms/VerticalLabel.tsx +20 -20
- package/src/components/forms/index.ts +11 -11
- package/src/components/forms/styles.ts +42 -42
- package/src/components/grid/DataGrid/DataGridCell.tsx +82 -82
- package/src/components/grid/DataGrid/DataGridColumnsModal/helpers.ts +9 -9
- package/src/components/grid/DataGrid/DataGridColumnsModal/hooks.tsx +59 -59
- package/src/components/grid/DataGrid/DataGridColumnsModal/index.tsx +182 -182
- package/src/components/grid/DataGrid/DataGridColumnsModal/styles.ts +104 -104
- package/src/components/grid/DataGrid/DataGridEditableCell/CheckboxEditableCell.tsx +37 -37
- package/src/components/grid/DataGrid/DataGridEditableCell/DateEditableCell.tsx +38 -38
- package/src/components/grid/DataGrid/DataGridEditableCell/NumberEditableCell.tsx +71 -71
- package/src/components/grid/DataGrid/DataGridEditableCell/TextEditableCell.tsx +37 -37
- package/src/components/grid/DataGrid/DataGridEditableCell/index.tsx +112 -112
- package/src/components/grid/DataGrid/DataGridEditableCell/styles.ts +35 -35
- package/src/components/grid/DataGrid/DataGridEditableCell/types.ts +18 -18
- package/src/components/grid/DataGrid/DataGridFilterMenu/FilterValuesScroller.tsx +129 -129
- package/src/components/grid/DataGrid/DataGridFilterMenu/helpers.ts +23 -23
- package/src/components/grid/DataGrid/DataGridFilterMenu/hooks.tsx +81 -81
- package/src/components/grid/DataGrid/DataGridFilterMenu/index.tsx +370 -370
- package/src/components/grid/DataGrid/DataGridFilterMenu/styles.ts +97 -97
- package/src/components/grid/DataGrid/DataGridFooter.tsx +48 -48
- package/src/components/grid/DataGrid/DataGridHeader.tsx +74 -74
- package/src/components/grid/DataGrid/DataGridHeaderCell.tsx +112 -112
- package/src/components/grid/DataGrid/DataGridRowTemplate.tsx +90 -90
- package/src/components/grid/DataGrid/DataGridToolbar.tsx +134 -134
- package/src/components/grid/DataGrid/FilterModalContent/index.tsx +137 -137
- package/src/components/grid/DataGrid/FilterModalContent/styles.ts +22 -22
- package/src/components/grid/DataGrid/constants.ts +6 -6
- package/src/components/grid/DataGrid/helpers/columns.tsx +458 -452
- package/src/components/grid/DataGrid/helpers/filters.ts +287 -287
- package/src/components/grid/DataGrid/helpers/index.ts +2 -2
- package/src/components/grid/DataGrid/hooks/index.ts +29 -29
- package/src/components/grid/DataGrid/hooks/useDataGrid.tsx +383 -383
- package/src/components/grid/DataGrid/hooks/useDataGridChangedRows.ts +97 -97
- package/src/components/grid/DataGrid/hooks/useDataGridCopy.ts +174 -174
- package/src/components/grid/DataGrid/hooks/useDataGridSettings.ts +48 -48
- package/src/components/grid/DataGrid/hooks/useRefreshModal.tsx +48 -48
- package/src/components/grid/DataGrid/index.tsx +111 -111
- package/src/components/grid/DataGrid/styles.ts +446 -446
- package/src/components/grid/DataGrid/types.ts +375 -380
- package/src/components/grid/SqlRequestDataGrid/helpers/columns.tsx +528 -526
- package/src/components/grid/SqlRequestDataGrid/helpers/index.ts +2 -2
- package/src/components/grid/SqlRequestDataGrid/helpers/rows.ts +24 -24
- package/src/components/grid/SqlRequestDataGrid/helpers/sqlRequests.ts +17 -17
- package/src/components/grid/SqlRequestDataGrid/index.tsx +417 -417
- package/src/components/grid/SqlRequestDataGrid/styles.ts +15 -15
- package/src/components/grid/SqlRequestDataGrid/types.ts +74 -74
- package/src/components/grid/SqlRequestForeignList/index.tsx +254 -254
- package/src/components/grid/SqlRequestForeignList/styles.ts +43 -43
- package/src/components/grid/SqlRequestForeignList/types.ts +32 -32
- package/src/components/grid/SqlRequestGrid/filters/FiltersSidebar.tsx +108 -108
- package/src/components/grid/SqlRequestGrid/filters/styles.ts +88 -88
- package/src/components/grid/SqlRequestGrid/helpers/index.ts +1 -1
- package/src/components/grid/SqlRequestGrid/helpers/sqlRequests.ts +16 -16
- package/src/components/grid/SqlRequestGrid/index.tsx +304 -304
- package/src/components/grid/SqlRequestGrid/styles.ts +20 -20
- package/src/components/grid/SqlRequestGrid/types.ts +73 -73
- package/src/components/grid/VirtualScroller/hooks.ts +71 -71
- package/src/components/grid/VirtualScroller/index.tsx +89 -89
- package/src/components/grid/VirtualScroller/styles.ts +57 -57
- package/src/components/grid/VirtualScroller/types.ts +10 -10
- package/src/components/grid/index.ts +11 -11
- package/src/components/layout/Columns.ts +28 -28
- package/src/components/layout/ContextMenu/ContextMenu.tsx +471 -471
- package/src/components/layout/ContextMenu/index.ts +23 -23
- package/src/components/layout/Dropdown/index.tsx +113 -113
- package/src/components/layout/Dropdown/styles.ts +53 -53
- package/src/components/layout/Flexbox.ts +21 -21
- package/src/components/layout/Grid/index.tsx +8 -8
- package/src/components/layout/Grid/styles.ts +34 -34
- package/src/components/layout/LeftMenu/LeftMenu.tsx +89 -89
- package/src/components/layout/LeftMenu/index.ts +2 -2
- package/src/components/layout/Loading/index.tsx +29 -29
- package/src/components/layout/Loading/styles.ts +29 -29
- package/src/components/layout/Masonry/index.tsx +29 -29
- package/src/components/layout/Masonry/styles.ts +20 -20
- package/src/components/layout/Modal/index.tsx +51 -51
- package/src/components/layout/Modal/styles.ts +125 -125
- package/src/components/layout/PanelContainer/PanelContainer.tsx +198 -198
- package/src/components/layout/PanelContainer/index.ts +2 -2
- package/src/components/layout/index.ts +10 -10
- package/src/components/search/HighlightedText.tsx +41 -41
- package/src/components/search/QuickSearchBar.tsx +125 -125
- package/src/components/search/QuickSearchResults.tsx +90 -90
- package/src/components/search/index.ts +5 -5
- package/src/components/search/styles.ts +96 -96
- package/src/components/search/types.ts +29 -29
- package/src/config/index.ts +10 -10
- package/src/helpers/cn.ts +6 -6
- package/src/helpers/components.ts +9 -9
- package/src/helpers/dates.ts +17 -17
- package/src/helpers/getScrollbarSize.ts +14 -14
- package/src/helpers/index.ts +8 -8
- package/src/helpers/numbers.ts +63 -63
- package/src/helpers/responsive.ts +83 -83
- package/src/helpers/styled/size.ts +24 -24
- package/src/helpers/styled/space.ts +111 -111
- package/src/helpers/styled/typography.ts +25 -25
- package/src/helpers/text.ts +13 -13
- package/src/helpers/types.ts +9 -9
- package/src/hooks/index.ts +9 -9
- package/src/hooks/providers.ts +14 -14
- package/src/hooks/useContainerMediaQuery.ts +7 -7
- package/src/hooks/useElementSize.ts +24 -24
- package/src/hooks/useMediaQuery.ts +9 -9
- package/src/hooks/useMediaQueryForWidth.ts +35 -35
- package/src/hooks/useMutableState.test.ts +410 -410
- package/src/hooks/useMutableState.ts +39 -39
- package/src/hooks/useShowArchived.ts +28 -28
- package/src/hooks/useWindowSize.ts +20 -20
- package/src/icons/index.tsx +138 -138
- package/src/providers/AuthenticationProvider/helpers.ts +3 -3
- package/src/providers/AuthenticationProvider/index.tsx +303 -303
- package/src/providers/LoadingProvider/index.tsx +47 -47
- package/src/providers/PortalsProvider/index.tsx +54 -54
- package/src/providers/PortalsProvider/styles.ts +31 -31
- package/src/providers/SettingsProvider/index.tsx +70 -70
- package/src/providers/ToastProvider/index.tsx +93 -93
- package/src/providers/TrackingProvider/hooks.ts +14 -14
- package/src/providers/TrackingProvider/index.tsx +71 -71
- package/src/providers/UiProviders/index.tsx +74 -74
- package/src/providers/UiProviders/styles.ts +10 -10
- package/src/providers/index.ts +6 -6
- package/src/services/HttpService.ts +92 -92
- package/src/services/WebSocketService.ts +155 -155
- package/src/services/advancedRequests.ts +102 -102
- package/src/services/base.ts +23 -23
- package/src/services/globalSearch.ts +32 -32
- package/src/services/hooks.ts +92 -92
- package/src/services/index.ts +20 -20
- package/src/services/requests/auth.ts +44 -44
- package/src/services/requests/generic.ts +76 -76
- package/src/services/requests/printing.ts +12 -12
- package/src/services/requests/tracking.ts +12 -12
- package/src/services/requests/userProfiles.ts +35 -35
- package/src/services/requests/users.ts +28 -28
- package/src/services/smartQueries.ts +122 -122
- package/src/services/sqlRequests.ts +119 -119
- package/src/services/types/auth.ts +98 -98
- package/src/services/types/base.ts +10 -10
- package/src/services/types/generic.ts +102 -102
- package/src/services/types/printing.ts +10 -10
- package/src/services/types/tracking.ts +29 -29
- package/src/services/types/userProfiles.ts +79 -79
- package/src/services/types/users.ts +74 -74
- package/src/services/updateSqlRequests.ts +32 -32
- package/src/styles/animations.scss +30 -30
- package/src/styles/index.scss +42 -42
- package/src/theme/ThemeProvider.ts +73 -73
- package/src/theme/defaultTheme.ts +471 -471
- package/src/theme/helpers.ts +89 -89
- package/src/theme/index.ts +4 -4
- package/src/theme/types.ts +139 -139
- package/src/types/index.ts +8 -8
- package/src/typings.d.ts +2 -2
- package/tsconfig.json +41 -41
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -1,379 +1,379 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
import React, {
|
|
4
|
-
ReactNode,
|
|
5
|
-
createContext,
|
|
6
|
-
useCallback,
|
|
7
|
-
useContext,
|
|
8
|
-
useState,
|
|
9
|
-
} from 'react';
|
|
10
|
-
|
|
11
|
-
type DropPosition = {
|
|
12
|
-
nodeId: string;
|
|
13
|
-
position: 'before' | 'after' | 'inside';
|
|
14
|
-
} | null;
|
|
15
|
-
|
|
16
|
-
export type DragDropType = 'none' | true | 'level';
|
|
17
|
-
|
|
18
|
-
interface TreeContextValue {
|
|
19
|
-
idPropertyName?: string;
|
|
20
|
-
childrenPropertyName?: string;
|
|
21
|
-
displayPropertyName?: string;
|
|
22
|
-
ItemComponent?: React.FC<{ item: any }>;
|
|
23
|
-
expandedIds: Set<string>;
|
|
24
|
-
toggleExpand: (id: string) => void;
|
|
25
|
-
isExpanded: (id: string) => boolean;
|
|
26
|
-
draggedNodeId: string | null;
|
|
27
|
-
draggedNodeLevel: number | null;
|
|
28
|
-
dropPosition: DropPosition;
|
|
29
|
-
dragDropType: DragDropType;
|
|
30
|
-
handleDragStart: (
|
|
31
|
-
e: React.DragEvent,
|
|
32
|
-
nodeId: string,
|
|
33
|
-
content: string,
|
|
34
|
-
level: number
|
|
35
|
-
) => void;
|
|
36
|
-
handleDragOver: (
|
|
37
|
-
e: React.DragEvent,
|
|
38
|
-
nodeId: string,
|
|
39
|
-
level: number,
|
|
40
|
-
isLastChild: boolean,
|
|
41
|
-
parentId: string | null,
|
|
42
|
-
hasChildren: boolean
|
|
43
|
-
) => void;
|
|
44
|
-
handleDragLeave: (e: React.DragEvent) => void;
|
|
45
|
-
handleDrop: (e: React.DragEvent) => void;
|
|
46
|
-
handleDragEnd: () => void;
|
|
47
|
-
handleDrag: (e: React.DragEvent) => void;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const TreeContext = createContext<TreeContextValue | null>(null);
|
|
51
|
-
|
|
52
|
-
export function useTreeContext() {
|
|
53
|
-
const context = useContext(TreeContext);
|
|
54
|
-
if (!context) {
|
|
55
|
-
throw new Error('TreeNode must be used within TreeView');
|
|
56
|
-
}
|
|
57
|
-
return context;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
interface TreeProviderProps {
|
|
61
|
-
children: ReactNode;
|
|
62
|
-
treeId: string;
|
|
63
|
-
items: any[];
|
|
64
|
-
idPropertyName?: string;
|
|
65
|
-
childrenPropertyName?: string;
|
|
66
|
-
displayPropertyName?: string;
|
|
67
|
-
ItemComponent?: React.FC<{ item: any }>;
|
|
68
|
-
defaultExpanded?: boolean;
|
|
69
|
-
dragDropType?: DragDropType;
|
|
70
|
-
onItemMove?: (
|
|
71
|
-
draggedId: string,
|
|
72
|
-
targetId: string,
|
|
73
|
-
position: 'before' | 'after' | 'inside'
|
|
74
|
-
) => void;
|
|
75
|
-
onItemsChanged?: (items: any[]) => void;
|
|
76
|
-
dragGhost: { x: number; y: number; content: string } | null;
|
|
77
|
-
setDragGhost: (
|
|
78
|
-
ghost: { x: number; y: number; content: string } | null
|
|
79
|
-
) => void;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function TreeProvider({
|
|
83
|
-
children,
|
|
84
|
-
treeId,
|
|
85
|
-
items,
|
|
86
|
-
idPropertyName,
|
|
87
|
-
childrenPropertyName,
|
|
88
|
-
displayPropertyName,
|
|
89
|
-
ItemComponent,
|
|
90
|
-
dragDropType = 'none',
|
|
91
|
-
onItemMove,
|
|
92
|
-
onItemsChanged,
|
|
93
|
-
dragGhost,
|
|
94
|
-
setDragGhost,
|
|
95
|
-
}: TreeProviderProps) {
|
|
96
|
-
const [expandedIds, setExpandedIds] = useState<Set<string>>(() => new Set());
|
|
97
|
-
const [draggedNodeId, setDraggedNodeId] = useState<string | null>(null);
|
|
98
|
-
const [draggedNodeLevel, setDraggedNodeLevel] = useState<number | null>(null);
|
|
99
|
-
const [dropPosition, setDropPosition] = useState<DropPosition>(null);
|
|
100
|
-
|
|
101
|
-
const defaultItemMove = useCallback(
|
|
102
|
-
(
|
|
103
|
-
draggedId: string,
|
|
104
|
-
targetId: string,
|
|
105
|
-
position: 'before' | 'after' | 'inside'
|
|
106
|
-
) => {
|
|
107
|
-
if (!onItemsChanged) return;
|
|
108
|
-
|
|
109
|
-
const clonedItems = structuredClone(items);
|
|
110
|
-
|
|
111
|
-
const getItemId = (item: any): string => {
|
|
112
|
-
if (idPropertyName && item[idPropertyName]) {
|
|
113
|
-
return String(item[idPropertyName]);
|
|
114
|
-
}
|
|
115
|
-
return String(item);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const findNodeAndParent = (
|
|
119
|
-
itemsArray: any[],
|
|
120
|
-
targetId: string
|
|
121
|
-
): { node: any; parent: any[] | null; index: number } | null => {
|
|
122
|
-
for (let i = 0; i < itemsArray.length; i++) {
|
|
123
|
-
const item = itemsArray[i];
|
|
124
|
-
if (getItemId(item) === targetId) {
|
|
125
|
-
return { node: item, parent: itemsArray, index: i };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (childrenPropertyName && item[childrenPropertyName]) {
|
|
129
|
-
const found = findNodeAndParent(
|
|
130
|
-
item[childrenPropertyName],
|
|
131
|
-
targetId
|
|
132
|
-
);
|
|
133
|
-
if (found) return found;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return null;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const draggedResult = findNodeAndParent(clonedItems, draggedId);
|
|
141
|
-
if (!draggedResult || !draggedResult.parent) return;
|
|
142
|
-
|
|
143
|
-
const {
|
|
144
|
-
node: draggedNode,
|
|
145
|
-
parent: draggedParent,
|
|
146
|
-
index: draggedIndex,
|
|
147
|
-
} = draggedResult;
|
|
148
|
-
draggedParent.splice(draggedIndex, 1);
|
|
149
|
-
|
|
150
|
-
const targetResult = findNodeAndParent(clonedItems, targetId);
|
|
151
|
-
if (!targetResult) return;
|
|
152
|
-
|
|
153
|
-
const {
|
|
154
|
-
node: targetNode,
|
|
155
|
-
parent: targetParent,
|
|
156
|
-
index: targetIndex,
|
|
157
|
-
} = targetResult;
|
|
158
|
-
|
|
159
|
-
if (position === 'inside') {
|
|
160
|
-
if (childrenPropertyName) {
|
|
161
|
-
if (!targetNode[childrenPropertyName]) {
|
|
162
|
-
targetNode[childrenPropertyName] = [];
|
|
163
|
-
}
|
|
164
|
-
targetNode[childrenPropertyName].push(draggedNode);
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
if (!targetParent) return;
|
|
168
|
-
|
|
169
|
-
const insertIndex =
|
|
170
|
-
position === 'before' ? targetIndex : targetIndex + 1;
|
|
171
|
-
targetParent.splice(insertIndex, 0, draggedNode);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
onItemsChanged(clonedItems);
|
|
175
|
-
},
|
|
176
|
-
[items, idPropertyName, childrenPropertyName, onItemsChanged]
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
const toggleExpand = useCallback((id: string) => {
|
|
180
|
-
setExpandedIds((prev) => {
|
|
181
|
-
const next = new Set(prev);
|
|
182
|
-
if (next.has(id)) {
|
|
183
|
-
next.delete(id);
|
|
184
|
-
} else {
|
|
185
|
-
next.add(id);
|
|
186
|
-
}
|
|
187
|
-
return next;
|
|
188
|
-
});
|
|
189
|
-
}, []);
|
|
190
|
-
|
|
191
|
-
const isExpanded = useCallback(
|
|
192
|
-
(id: string) => {
|
|
193
|
-
return expandedIds.has(id);
|
|
194
|
-
},
|
|
195
|
-
[expandedIds]
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
const handleDragStart = useCallback(
|
|
199
|
-
(e: React.DragEvent, nodeId: string, content: string, level: number) => {
|
|
200
|
-
if (dragDropType === 'none') {
|
|
201
|
-
e.preventDefault();
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
setDraggedNodeId(nodeId);
|
|
206
|
-
setDraggedNodeLevel(level);
|
|
207
|
-
|
|
208
|
-
e.dataTransfer.setData('text/plain', treeId);
|
|
209
|
-
e.dataTransfer.setData('application/x-tree-id', treeId);
|
|
210
|
-
|
|
211
|
-
const img = new Image();
|
|
212
|
-
img.src =
|
|
213
|
-
'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=';
|
|
214
|
-
e.dataTransfer.effectAllowed = 'move';
|
|
215
|
-
e.dataTransfer.setDragImage(img, 0, 0);
|
|
216
|
-
|
|
217
|
-
setDragGhost({ x: e.clientX, y: e.clientY, content });
|
|
218
|
-
},
|
|
219
|
-
[treeId, setDragGhost, dragDropType]
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
const handleDragOver = useCallback(
|
|
223
|
-
(
|
|
224
|
-
e: React.DragEvent,
|
|
225
|
-
nodeId: string,
|
|
226
|
-
level: number,
|
|
227
|
-
isLastChild: boolean,
|
|
228
|
-
parentId: string | null,
|
|
229
|
-
hasChildren: boolean
|
|
230
|
-
) => {
|
|
231
|
-
e.preventDefault();
|
|
232
|
-
e.stopPropagation();
|
|
233
|
-
|
|
234
|
-
const draggedFromTreeId = e.dataTransfer.types.includes(
|
|
235
|
-
'application/x-tree-id'
|
|
236
|
-
)
|
|
237
|
-
? e.dataTransfer.getData('application/x-tree-id') ||
|
|
238
|
-
e.dataTransfer.getData('text/plain')
|
|
239
|
-
: null;
|
|
240
|
-
|
|
241
|
-
if (draggedFromTreeId && draggedFromTreeId !== treeId) {
|
|
242
|
-
setDropPosition(null);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (draggedNodeId === nodeId) {
|
|
247
|
-
setDropPosition(null);
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (draggedNodeId && nodeId.startsWith(draggedNodeId + '-')) {
|
|
252
|
-
setDropPosition(null);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (
|
|
257
|
-
dragDropType === 'level' &&
|
|
258
|
-
draggedNodeLevel !== null &&
|
|
259
|
-
draggedNodeLevel !== level
|
|
260
|
-
) {
|
|
261
|
-
setDropPosition(null);
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const rect = e.currentTarget.getBoundingClientRect();
|
|
266
|
-
const relativeY = e.clientY - rect.top;
|
|
267
|
-
const height = rect.height;
|
|
268
|
-
|
|
269
|
-
let newPosition: 'before' | 'after' | 'inside';
|
|
270
|
-
|
|
271
|
-
if (hasChildren) {
|
|
272
|
-
const threshold = height * 0.4;
|
|
273
|
-
if (relativeY < threshold) {
|
|
274
|
-
newPosition = 'before';
|
|
275
|
-
} else {
|
|
276
|
-
newPosition = 'inside';
|
|
277
|
-
}
|
|
278
|
-
} else {
|
|
279
|
-
if (relativeY < height / 2) {
|
|
280
|
-
newPosition = 'before';
|
|
281
|
-
} else {
|
|
282
|
-
newPosition = 'after';
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (dragDropType === 'level' && newPosition === 'inside') {
|
|
287
|
-
setDropPosition(null);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
setDropPosition({ nodeId, position: newPosition });
|
|
292
|
-
},
|
|
293
|
-
[treeId, draggedNodeId, dragDropType, draggedNodeLevel]
|
|
294
|
-
);
|
|
295
|
-
|
|
296
|
-
const handleDragLeave = useCallback((e: React.DragEvent) => {
|
|
297
|
-
e.preventDefault();
|
|
298
|
-
const relatedTarget = e.relatedTarget as HTMLElement;
|
|
299
|
-
if (!relatedTarget || !e.currentTarget.contains(relatedTarget)) {
|
|
300
|
-
setDropPosition(null);
|
|
301
|
-
}
|
|
302
|
-
}, []);
|
|
303
|
-
|
|
304
|
-
const handleDrop = useCallback(
|
|
305
|
-
(e: React.DragEvent) => {
|
|
306
|
-
e.preventDefault();
|
|
307
|
-
e.stopPropagation();
|
|
308
|
-
|
|
309
|
-
const draggedFromTreeId =
|
|
310
|
-
e.dataTransfer.getData('application/x-tree-id') ||
|
|
311
|
-
e.dataTransfer.getData('text/plain');
|
|
312
|
-
|
|
313
|
-
if (draggedFromTreeId !== treeId) {
|
|
314
|
-
setDraggedNodeId(null);
|
|
315
|
-
setDropPosition(null);
|
|
316
|
-
setDragGhost(null);
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
if (draggedNodeId && dropPosition) {
|
|
321
|
-
const moveHandler = onItemMove || defaultItemMove;
|
|
322
|
-
moveHandler(draggedNodeId, dropPosition.nodeId, dropPosition.position);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
setDraggedNodeId(null);
|
|
326
|
-
setDropPosition(null);
|
|
327
|
-
setDragGhost(null);
|
|
328
|
-
},
|
|
329
|
-
[
|
|
330
|
-
treeId,
|
|
331
|
-
draggedNodeId,
|
|
332
|
-
dropPosition,
|
|
333
|
-
onItemMove,
|
|
334
|
-
defaultItemMove,
|
|
335
|
-
setDragGhost,
|
|
336
|
-
]
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
const handleDragEnd = useCallback(() => {
|
|
340
|
-
setDraggedNodeId(null);
|
|
341
|
-
setDraggedNodeLevel(null);
|
|
342
|
-
setDropPosition(null);
|
|
343
|
-
setDragGhost(null);
|
|
344
|
-
}, [setDragGhost]);
|
|
345
|
-
|
|
346
|
-
const handleDrag = useCallback(
|
|
347
|
-
(e: React.DragEvent) => {
|
|
348
|
-
if (e.clientX === 0 && e.clientY === 0) return;
|
|
349
|
-
if (dragGhost) {
|
|
350
|
-
setDragGhost({ ...dragGhost, x: e.clientX, y: e.clientY });
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
|
-
[dragGhost, setDragGhost]
|
|
354
|
-
);
|
|
355
|
-
|
|
356
|
-
const contextValue: TreeContextValue = {
|
|
357
|
-
idPropertyName,
|
|
358
|
-
childrenPropertyName,
|
|
359
|
-
displayPropertyName,
|
|
360
|
-
ItemComponent,
|
|
361
|
-
expandedIds,
|
|
362
|
-
toggleExpand,
|
|
363
|
-
isExpanded,
|
|
364
|
-
draggedNodeId,
|
|
365
|
-
draggedNodeLevel,
|
|
366
|
-
dropPosition,
|
|
367
|
-
dragDropType,
|
|
368
|
-
handleDragStart,
|
|
369
|
-
handleDragOver,
|
|
370
|
-
handleDragLeave,
|
|
371
|
-
handleDrop,
|
|
372
|
-
handleDragEnd,
|
|
373
|
-
handleDrag,
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
return (
|
|
377
|
-
<TreeContext.Provider value={contextValue}>{children}</TreeContext.Provider>
|
|
378
|
-
);
|
|
379
|
-
}
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import React, {
|
|
4
|
+
ReactNode,
|
|
5
|
+
createContext,
|
|
6
|
+
useCallback,
|
|
7
|
+
useContext,
|
|
8
|
+
useState,
|
|
9
|
+
} from 'react';
|
|
10
|
+
|
|
11
|
+
type DropPosition = {
|
|
12
|
+
nodeId: string;
|
|
13
|
+
position: 'before' | 'after' | 'inside';
|
|
14
|
+
} | null;
|
|
15
|
+
|
|
16
|
+
export type DragDropType = 'none' | true | 'level';
|
|
17
|
+
|
|
18
|
+
interface TreeContextValue {
|
|
19
|
+
idPropertyName?: string;
|
|
20
|
+
childrenPropertyName?: string;
|
|
21
|
+
displayPropertyName?: string;
|
|
22
|
+
ItemComponent?: React.FC<{ item: any }>;
|
|
23
|
+
expandedIds: Set<string>;
|
|
24
|
+
toggleExpand: (id: string) => void;
|
|
25
|
+
isExpanded: (id: string) => boolean;
|
|
26
|
+
draggedNodeId: string | null;
|
|
27
|
+
draggedNodeLevel: number | null;
|
|
28
|
+
dropPosition: DropPosition;
|
|
29
|
+
dragDropType: DragDropType;
|
|
30
|
+
handleDragStart: (
|
|
31
|
+
e: React.DragEvent,
|
|
32
|
+
nodeId: string,
|
|
33
|
+
content: string,
|
|
34
|
+
level: number
|
|
35
|
+
) => void;
|
|
36
|
+
handleDragOver: (
|
|
37
|
+
e: React.DragEvent,
|
|
38
|
+
nodeId: string,
|
|
39
|
+
level: number,
|
|
40
|
+
isLastChild: boolean,
|
|
41
|
+
parentId: string | null,
|
|
42
|
+
hasChildren: boolean
|
|
43
|
+
) => void;
|
|
44
|
+
handleDragLeave: (e: React.DragEvent) => void;
|
|
45
|
+
handleDrop: (e: React.DragEvent) => void;
|
|
46
|
+
handleDragEnd: () => void;
|
|
47
|
+
handleDrag: (e: React.DragEvent) => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const TreeContext = createContext<TreeContextValue | null>(null);
|
|
51
|
+
|
|
52
|
+
export function useTreeContext() {
|
|
53
|
+
const context = useContext(TreeContext);
|
|
54
|
+
if (!context) {
|
|
55
|
+
throw new Error('TreeNode must be used within TreeView');
|
|
56
|
+
}
|
|
57
|
+
return context;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface TreeProviderProps {
|
|
61
|
+
children: ReactNode;
|
|
62
|
+
treeId: string;
|
|
63
|
+
items: any[];
|
|
64
|
+
idPropertyName?: string;
|
|
65
|
+
childrenPropertyName?: string;
|
|
66
|
+
displayPropertyName?: string;
|
|
67
|
+
ItemComponent?: React.FC<{ item: any }>;
|
|
68
|
+
defaultExpanded?: boolean;
|
|
69
|
+
dragDropType?: DragDropType;
|
|
70
|
+
onItemMove?: (
|
|
71
|
+
draggedId: string,
|
|
72
|
+
targetId: string,
|
|
73
|
+
position: 'before' | 'after' | 'inside'
|
|
74
|
+
) => void;
|
|
75
|
+
onItemsChanged?: (items: any[]) => void;
|
|
76
|
+
dragGhost: { x: number; y: number; content: string } | null;
|
|
77
|
+
setDragGhost: (
|
|
78
|
+
ghost: { x: number; y: number; content: string } | null
|
|
79
|
+
) => void;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function TreeProvider({
|
|
83
|
+
children,
|
|
84
|
+
treeId,
|
|
85
|
+
items,
|
|
86
|
+
idPropertyName,
|
|
87
|
+
childrenPropertyName,
|
|
88
|
+
displayPropertyName,
|
|
89
|
+
ItemComponent,
|
|
90
|
+
dragDropType = 'none',
|
|
91
|
+
onItemMove,
|
|
92
|
+
onItemsChanged,
|
|
93
|
+
dragGhost,
|
|
94
|
+
setDragGhost,
|
|
95
|
+
}: TreeProviderProps) {
|
|
96
|
+
const [expandedIds, setExpandedIds] = useState<Set<string>>(() => new Set());
|
|
97
|
+
const [draggedNodeId, setDraggedNodeId] = useState<string | null>(null);
|
|
98
|
+
const [draggedNodeLevel, setDraggedNodeLevel] = useState<number | null>(null);
|
|
99
|
+
const [dropPosition, setDropPosition] = useState<DropPosition>(null);
|
|
100
|
+
|
|
101
|
+
const defaultItemMove = useCallback(
|
|
102
|
+
(
|
|
103
|
+
draggedId: string,
|
|
104
|
+
targetId: string,
|
|
105
|
+
position: 'before' | 'after' | 'inside'
|
|
106
|
+
) => {
|
|
107
|
+
if (!onItemsChanged) return;
|
|
108
|
+
|
|
109
|
+
const clonedItems = structuredClone(items);
|
|
110
|
+
|
|
111
|
+
const getItemId = (item: any): string => {
|
|
112
|
+
if (idPropertyName && item[idPropertyName]) {
|
|
113
|
+
return String(item[idPropertyName]);
|
|
114
|
+
}
|
|
115
|
+
return String(item);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const findNodeAndParent = (
|
|
119
|
+
itemsArray: any[],
|
|
120
|
+
targetId: string
|
|
121
|
+
): { node: any; parent: any[] | null; index: number } | null => {
|
|
122
|
+
for (let i = 0; i < itemsArray.length; i++) {
|
|
123
|
+
const item = itemsArray[i];
|
|
124
|
+
if (getItemId(item) === targetId) {
|
|
125
|
+
return { node: item, parent: itemsArray, index: i };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (childrenPropertyName && item[childrenPropertyName]) {
|
|
129
|
+
const found = findNodeAndParent(
|
|
130
|
+
item[childrenPropertyName],
|
|
131
|
+
targetId
|
|
132
|
+
);
|
|
133
|
+
if (found) return found;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return null;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const draggedResult = findNodeAndParent(clonedItems, draggedId);
|
|
141
|
+
if (!draggedResult || !draggedResult.parent) return;
|
|
142
|
+
|
|
143
|
+
const {
|
|
144
|
+
node: draggedNode,
|
|
145
|
+
parent: draggedParent,
|
|
146
|
+
index: draggedIndex,
|
|
147
|
+
} = draggedResult;
|
|
148
|
+
draggedParent.splice(draggedIndex, 1);
|
|
149
|
+
|
|
150
|
+
const targetResult = findNodeAndParent(clonedItems, targetId);
|
|
151
|
+
if (!targetResult) return;
|
|
152
|
+
|
|
153
|
+
const {
|
|
154
|
+
node: targetNode,
|
|
155
|
+
parent: targetParent,
|
|
156
|
+
index: targetIndex,
|
|
157
|
+
} = targetResult;
|
|
158
|
+
|
|
159
|
+
if (position === 'inside') {
|
|
160
|
+
if (childrenPropertyName) {
|
|
161
|
+
if (!targetNode[childrenPropertyName]) {
|
|
162
|
+
targetNode[childrenPropertyName] = [];
|
|
163
|
+
}
|
|
164
|
+
targetNode[childrenPropertyName].push(draggedNode);
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
if (!targetParent) return;
|
|
168
|
+
|
|
169
|
+
const insertIndex =
|
|
170
|
+
position === 'before' ? targetIndex : targetIndex + 1;
|
|
171
|
+
targetParent.splice(insertIndex, 0, draggedNode);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
onItemsChanged(clonedItems);
|
|
175
|
+
},
|
|
176
|
+
[items, idPropertyName, childrenPropertyName, onItemsChanged]
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const toggleExpand = useCallback((id: string) => {
|
|
180
|
+
setExpandedIds((prev) => {
|
|
181
|
+
const next = new Set(prev);
|
|
182
|
+
if (next.has(id)) {
|
|
183
|
+
next.delete(id);
|
|
184
|
+
} else {
|
|
185
|
+
next.add(id);
|
|
186
|
+
}
|
|
187
|
+
return next;
|
|
188
|
+
});
|
|
189
|
+
}, []);
|
|
190
|
+
|
|
191
|
+
const isExpanded = useCallback(
|
|
192
|
+
(id: string) => {
|
|
193
|
+
return expandedIds.has(id);
|
|
194
|
+
},
|
|
195
|
+
[expandedIds]
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const handleDragStart = useCallback(
|
|
199
|
+
(e: React.DragEvent, nodeId: string, content: string, level: number) => {
|
|
200
|
+
if (dragDropType === 'none') {
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
setDraggedNodeId(nodeId);
|
|
206
|
+
setDraggedNodeLevel(level);
|
|
207
|
+
|
|
208
|
+
e.dataTransfer.setData('text/plain', treeId);
|
|
209
|
+
e.dataTransfer.setData('application/x-tree-id', treeId);
|
|
210
|
+
|
|
211
|
+
const img = new Image();
|
|
212
|
+
img.src =
|
|
213
|
+
'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=';
|
|
214
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
215
|
+
e.dataTransfer.setDragImage(img, 0, 0);
|
|
216
|
+
|
|
217
|
+
setDragGhost({ x: e.clientX, y: e.clientY, content });
|
|
218
|
+
},
|
|
219
|
+
[treeId, setDragGhost, dragDropType]
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const handleDragOver = useCallback(
|
|
223
|
+
(
|
|
224
|
+
e: React.DragEvent,
|
|
225
|
+
nodeId: string,
|
|
226
|
+
level: number,
|
|
227
|
+
isLastChild: boolean,
|
|
228
|
+
parentId: string | null,
|
|
229
|
+
hasChildren: boolean
|
|
230
|
+
) => {
|
|
231
|
+
e.preventDefault();
|
|
232
|
+
e.stopPropagation();
|
|
233
|
+
|
|
234
|
+
const draggedFromTreeId = e.dataTransfer.types.includes(
|
|
235
|
+
'application/x-tree-id'
|
|
236
|
+
)
|
|
237
|
+
? e.dataTransfer.getData('application/x-tree-id') ||
|
|
238
|
+
e.dataTransfer.getData('text/plain')
|
|
239
|
+
: null;
|
|
240
|
+
|
|
241
|
+
if (draggedFromTreeId && draggedFromTreeId !== treeId) {
|
|
242
|
+
setDropPosition(null);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (draggedNodeId === nodeId) {
|
|
247
|
+
setDropPosition(null);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (draggedNodeId && nodeId.startsWith(draggedNodeId + '-')) {
|
|
252
|
+
setDropPosition(null);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (
|
|
257
|
+
dragDropType === 'level' &&
|
|
258
|
+
draggedNodeLevel !== null &&
|
|
259
|
+
draggedNodeLevel !== level
|
|
260
|
+
) {
|
|
261
|
+
setDropPosition(null);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
266
|
+
const relativeY = e.clientY - rect.top;
|
|
267
|
+
const height = rect.height;
|
|
268
|
+
|
|
269
|
+
let newPosition: 'before' | 'after' | 'inside';
|
|
270
|
+
|
|
271
|
+
if (hasChildren) {
|
|
272
|
+
const threshold = height * 0.4;
|
|
273
|
+
if (relativeY < threshold) {
|
|
274
|
+
newPosition = 'before';
|
|
275
|
+
} else {
|
|
276
|
+
newPosition = 'inside';
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
if (relativeY < height / 2) {
|
|
280
|
+
newPosition = 'before';
|
|
281
|
+
} else {
|
|
282
|
+
newPosition = 'after';
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (dragDropType === 'level' && newPosition === 'inside') {
|
|
287
|
+
setDropPosition(null);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
setDropPosition({ nodeId, position: newPosition });
|
|
292
|
+
},
|
|
293
|
+
[treeId, draggedNodeId, dragDropType, draggedNodeLevel]
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
const handleDragLeave = useCallback((e: React.DragEvent) => {
|
|
297
|
+
e.preventDefault();
|
|
298
|
+
const relatedTarget = e.relatedTarget as HTMLElement;
|
|
299
|
+
if (!relatedTarget || !e.currentTarget.contains(relatedTarget)) {
|
|
300
|
+
setDropPosition(null);
|
|
301
|
+
}
|
|
302
|
+
}, []);
|
|
303
|
+
|
|
304
|
+
const handleDrop = useCallback(
|
|
305
|
+
(e: React.DragEvent) => {
|
|
306
|
+
e.preventDefault();
|
|
307
|
+
e.stopPropagation();
|
|
308
|
+
|
|
309
|
+
const draggedFromTreeId =
|
|
310
|
+
e.dataTransfer.getData('application/x-tree-id') ||
|
|
311
|
+
e.dataTransfer.getData('text/plain');
|
|
312
|
+
|
|
313
|
+
if (draggedFromTreeId !== treeId) {
|
|
314
|
+
setDraggedNodeId(null);
|
|
315
|
+
setDropPosition(null);
|
|
316
|
+
setDragGhost(null);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (draggedNodeId && dropPosition) {
|
|
321
|
+
const moveHandler = onItemMove || defaultItemMove;
|
|
322
|
+
moveHandler(draggedNodeId, dropPosition.nodeId, dropPosition.position);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
setDraggedNodeId(null);
|
|
326
|
+
setDropPosition(null);
|
|
327
|
+
setDragGhost(null);
|
|
328
|
+
},
|
|
329
|
+
[
|
|
330
|
+
treeId,
|
|
331
|
+
draggedNodeId,
|
|
332
|
+
dropPosition,
|
|
333
|
+
onItemMove,
|
|
334
|
+
defaultItemMove,
|
|
335
|
+
setDragGhost,
|
|
336
|
+
]
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
const handleDragEnd = useCallback(() => {
|
|
340
|
+
setDraggedNodeId(null);
|
|
341
|
+
setDraggedNodeLevel(null);
|
|
342
|
+
setDropPosition(null);
|
|
343
|
+
setDragGhost(null);
|
|
344
|
+
}, [setDragGhost]);
|
|
345
|
+
|
|
346
|
+
const handleDrag = useCallback(
|
|
347
|
+
(e: React.DragEvent) => {
|
|
348
|
+
if (e.clientX === 0 && e.clientY === 0) return;
|
|
349
|
+
if (dragGhost) {
|
|
350
|
+
setDragGhost({ ...dragGhost, x: e.clientX, y: e.clientY });
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
[dragGhost, setDragGhost]
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
const contextValue: TreeContextValue = {
|
|
357
|
+
idPropertyName,
|
|
358
|
+
childrenPropertyName,
|
|
359
|
+
displayPropertyName,
|
|
360
|
+
ItemComponent,
|
|
361
|
+
expandedIds,
|
|
362
|
+
toggleExpand,
|
|
363
|
+
isExpanded,
|
|
364
|
+
draggedNodeId,
|
|
365
|
+
draggedNodeLevel,
|
|
366
|
+
dropPosition,
|
|
367
|
+
dragDropType,
|
|
368
|
+
handleDragStart,
|
|
369
|
+
handleDragOver,
|
|
370
|
+
handleDragLeave,
|
|
371
|
+
handleDrop,
|
|
372
|
+
handleDragEnd,
|
|
373
|
+
handleDrag,
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
return (
|
|
377
|
+
<TreeContext.Provider value={contextValue}>{children}</TreeContext.Provider>
|
|
378
|
+
);
|
|
379
|
+
}
|