pixel-priya 1.2.83 → 1.2.85
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/lib/components/AddResourceButton/AddResourceButton.js +19 -14
- package/lib/components/AddResourceButton/AddResourceButton.js.map +1 -1
- package/lib/components/AttachmentButton/AttachmentButton.js +2 -0
- package/lib/components/AttachmentButton/AttachmentButton.js.map +1 -1
- package/lib/components/Charts/DonutChart/DonutChart.js +24 -16
- package/lib/components/Charts/DonutChart/DonutChart.js.map +1 -1
- package/lib/components/Charts/DonutChart/type.d.ts +4 -1
- package/lib/components/ConditionalDropdown/ConditionalDropdown.js +2 -1
- package/lib/components/ConditionalDropdown/ConditionalDropdown.js.map +1 -1
- package/lib/components/Editor/Editor.js +1 -1
- package/lib/components/Editor/Editor.js.map +1 -1
- package/lib/components/Editor/constants.js +121 -40
- package/lib/components/Editor/constants.js.map +1 -1
- package/lib/components/Excel/ColorBarSelector/ColorBarSelector.d.ts +1 -1
- package/lib/components/Excel/ColorBarSelector/ColorBarSelector.js +5 -3
- package/lib/components/Excel/ColorBarSelector/ColorBarSelector.js.map +1 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/ActiveCell.js +6 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/ActiveCell.js.map +1 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.js +10 -3
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.js.map +1 -1
- package/lib/components/Excel/ExcelToolBar/ExcelToolBar.js +8 -2
- package/lib/components/Excel/ExcelToolBar/ExcelToolBar.js.map +1 -1
- package/lib/components/Icon/iconList.js +16 -0
- package/lib/components/Icon/iconList.js.map +1 -1
- package/lib/components/MediaPreview/MediaPreview.js +1 -1
- package/lib/components/MediaPreview/MediaPreview.js.map +1 -1
- package/lib/components/MediaViewerModal/type.d.ts +1 -1
- package/lib/components/MenuOption/MenuOption.js +2 -13
- package/lib/components/MenuOption/MenuOption.js.map +1 -1
- package/lib/components/MultiSelect/Dropdown.js +2 -1
- package/lib/components/MultiSelect/Dropdown.js.map +1 -1
- package/lib/components/PrePostTable/components/DraggableTableRow.js +4 -1
- package/lib/components/PrePostTable/components/DraggableTableRow.js.map +1 -1
- package/lib/components/PrePostTable/components/PrePostStepAccordions.js +14 -3
- package/lib/components/PrePostTable/components/PrePostStepAccordions.js.map +1 -1
- package/lib/components/Select/Select.js +3 -3
- package/lib/components/Select/Select.js.map +1 -1
- package/lib/components/SessionDropdown/SessionDropdown.js +4 -4
- package/lib/components/SessionDropdown/SessionDropdown.js.map +1 -1
- package/lib/components/SessionDropdown/type.d.ts +2 -0
- package/lib/components/StatusBadge/StatusBadge.d.ts +2 -1
- package/lib/components/StatusBadge/StatusBadge.js +3 -3
- package/lib/components/StatusBadge/StatusBadge.js.map +1 -1
- package/lib/components/StatusButton/types.d.ts +1 -1
- package/lib/components/StepsLandingTable/Components/StepGroupAccordions.js +7 -4
- package/lib/components/StepsLandingTable/Components/StepGroupAccordions.js.map +1 -1
- package/lib/components/StepsLandingTable/Components/StepTableMainRow.js +5 -3
- package/lib/components/StepsLandingTable/Components/StepTableMainRow.js.map +1 -1
- package/lib/components/TableTreeFn/Components/TableBody.d.ts +1 -1
- package/lib/components/TableTreeFn/Components/TableBody.js +12 -7
- package/lib/components/TableTreeFn/Components/TableBody.js.map +1 -1
- package/lib/components/TableTreeFn/Components/TableCell.d.ts +1 -1
- package/lib/components/TableTreeFn/Components/TableCell.js +25 -17
- package/lib/components/TableTreeFn/Components/TableCell.js.map +1 -1
- package/lib/components/TableTreeFn/Components/TableHead.d.ts +1 -1
- package/lib/components/TableTreeFn/Components/TableHead.js +27 -17
- package/lib/components/TableTreeFn/Components/TableHead.js.map +1 -1
- package/lib/components/TableTreeFn/Components/TableRow.d.ts +1 -1
- package/lib/components/TableTreeFn/Components/TableRow.js +10 -2
- package/lib/components/TableTreeFn/Components/TableRow.js.map +1 -1
- package/lib/components/TableTreeFn/TableTreeFn.d.ts +1 -1
- package/lib/components/TableTreeFn/TableTreeFn.js +709 -247
- package/lib/components/TableTreeFn/TableTreeFn.js.map +1 -1
- package/lib/components/TableTreeFn/Utils/TableCell.d.ts +1 -0
- package/lib/components/TableTreeFn/Utils/TableCell.js +24 -0
- package/lib/components/TableTreeFn/Utils/TableCell.js.map +1 -0
- package/lib/components/TableTreeFn/Utils/addLastChild.d.ts +1 -1
- package/lib/components/TableTreeFn/Utils/addLastChild.js +2 -2
- package/lib/components/TableTreeFn/Utils/addLastChild.js.map +1 -1
- package/lib/components/TableTreeFn/Utils/addNewRow.js +6 -5
- package/lib/components/TableTreeFn/Utils/addNewRow.js.map +1 -1
- package/lib/components/TableTreeFn/Utils/formatDataCell.js +1 -1
- package/lib/components/TableTreeFn/Utils/formatDataCell.js.map +1 -1
- package/lib/components/TableTreeFn/Utils/updateParentSibling.d.ts +1 -1
- package/lib/components/TableTreeFn/Utils/updateParentSibling.js +7 -7
- package/lib/components/TableTreeFn/Utils/updateParentSibling.js.map +1 -1
- package/lib/components/TableTreeFn/index.d.ts +2 -0
- package/lib/components/TableTreeFn/index.js +2 -0
- package/lib/components/TableTreeFn/index.js.map +1 -1
- package/lib/components/TableTreeFn/types.d.ts +40 -7
- package/lib/index.d.ts +13 -4
- package/lib/index.js +8 -8
- package/lib/index.js.map +1 -1
- package/lib/styles.css +1 -1
- package/lib/styles.css.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/AddStepGroup/AddStepGroup.js +5 -2
- package/lib/utils/AddStepGroup/AddStepGroup.js.map +1 -1
- package/lib/utils/converToCamelCase.d.ts +1 -0
- package/lib/utils/converToCamelCase.js +6 -0
- package/lib/utils/converToCamelCase.js.map +1 -0
- package/lib/utils/getTopVisibleNodeKey/getTopVisibleNodeKey.js +8 -9
- package/lib/utils/getTopVisibleNodeKey/getTopVisibleNodeKey.js.map +1 -1
- package/package.json +25 -16
|
@@ -1,242 +1,741 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
import '
|
|
4
|
-
import
|
|
2
|
+
/* eslint-disable max-lines */
|
|
3
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, forwardRef, } from 'react';
|
|
4
|
+
import './TableTreeFn.scss';
|
|
5
5
|
import TableBody from './Components/TableBody';
|
|
6
|
-
import
|
|
7
|
-
import { checkEmpty } from '../../utils/checkEmpty/checkEmpty';
|
|
6
|
+
import TableHead from './Components/TableHead';
|
|
8
7
|
import { debounce } from '../../utils/debounce/debounce';
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import { checkEmpty } from '../../utils/checkEmpty/checkEmpty';
|
|
9
|
+
const DEFAULT_COLUMN_WIDTH = 400;
|
|
10
|
+
const ROW_HEIGHT = 32;
|
|
11
|
+
const OVERSCAN = 6;
|
|
12
|
+
const ROOT_PARENT_ID = '__root__';
|
|
13
|
+
const insertNewNode = (treeData, newNode, rootNode) => {
|
|
14
|
+
if (!newNode?.sourceId || !newNode.action)
|
|
15
|
+
return treeData;
|
|
16
|
+
const { sourceId, action, value = '', error = '', label, type, options, selectedOption, confirmIconTooltip, cancelIconTooltip, payloadSourceId, } = newNode;
|
|
17
|
+
const fallbackParentId = newNode
|
|
18
|
+
?.parentId;
|
|
19
|
+
const fallbackHierarchy = newNode
|
|
20
|
+
?.hierarchy;
|
|
21
|
+
const convertedOptions = options?.map((option) => ({
|
|
22
|
+
label: option,
|
|
23
|
+
value: option,
|
|
24
|
+
}));
|
|
25
|
+
const convertedSelectedOption = selectedOption
|
|
26
|
+
? { label: selectedOption, value: selectedOption }
|
|
27
|
+
: undefined;
|
|
28
|
+
const nodeMap = new Map();
|
|
29
|
+
treeData.forEach((node) => nodeMap.set(node.key, node));
|
|
30
|
+
if (rootNode) {
|
|
31
|
+
nodeMap.set(rootNode.key, rootNode);
|
|
32
|
+
}
|
|
33
|
+
const sourceNode = nodeMap.get(sourceId);
|
|
34
|
+
let payloadSourceNode;
|
|
35
|
+
if (payloadSourceId) {
|
|
36
|
+
payloadSourceNode = nodeMap.get(payloadSourceId);
|
|
37
|
+
}
|
|
38
|
+
// For add-inside flows, backend can return navigateTo as a parent key or a
|
|
39
|
+
// key not present in the current page. Fallback to payload source when possible.
|
|
40
|
+
let effectiveSourceNode = sourceNode ?? (action === 'addInside' ? payloadSourceNode : undefined);
|
|
41
|
+
if (!effectiveSourceNode && action === 'addInside' && fallbackParentId) {
|
|
42
|
+
effectiveSourceNode = nodeMap.get(fallbackParentId);
|
|
43
|
+
}
|
|
44
|
+
const fallbackInsertAtEnd = action === 'addInside' && !effectiveSourceNode && treeData.length >= 0;
|
|
45
|
+
if (!effectiveSourceNode && !fallbackInsertAtEnd)
|
|
46
|
+
return treeData;
|
|
47
|
+
const updatedTreeData = [...treeData];
|
|
48
|
+
const sourceIndex = effectiveSourceNode
|
|
49
|
+
? treeData.findIndex((node) => node.key === effectiveSourceNode.key)
|
|
50
|
+
: -1;
|
|
51
|
+
let newNodeParentId = null;
|
|
52
|
+
let newNodeHierarchy = 0;
|
|
53
|
+
let insertionIndex = sourceIndex + 1;
|
|
54
|
+
switch (action) {
|
|
55
|
+
case 'addAbove': {
|
|
56
|
+
const sourceNodeForInsert = effectiveSourceNode;
|
|
57
|
+
if (!sourceNodeForInsert)
|
|
58
|
+
return treeData;
|
|
59
|
+
newNodeParentId = sourceNodeForInsert.parentId;
|
|
60
|
+
newNodeHierarchy = sourceNodeForInsert.hierarchy;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'addBelow': {
|
|
64
|
+
const sourceNodeForInsert = effectiveSourceNode;
|
|
65
|
+
if (!sourceNodeForInsert)
|
|
66
|
+
return treeData;
|
|
67
|
+
newNodeParentId =
|
|
68
|
+
payloadSourceNode?.parentId ?? sourceNodeForInsert.parentId;
|
|
69
|
+
newNodeHierarchy =
|
|
70
|
+
payloadSourceNode?.hierarchy ?? sourceNodeForInsert.hierarchy;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case 'addInside': {
|
|
74
|
+
if (fallbackInsertAtEnd) {
|
|
75
|
+
newNodeParentId =
|
|
76
|
+
fallbackParentId ?? payloadSourceId ?? sourceId ?? null;
|
|
77
|
+
newNodeHierarchy = fallbackHierarchy ?? 1;
|
|
78
|
+
insertionIndex = updatedTreeData.length;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
const parentNode = payloadSourceNode ?? effectiveSourceNode;
|
|
82
|
+
if (!parentNode)
|
|
83
|
+
return treeData;
|
|
84
|
+
newNodeParentId = parentNode.key;
|
|
85
|
+
newNodeHierarchy = (parentNode.hierarchy ?? 0) + 1;
|
|
86
|
+
// Keep add-inside input at the end of the current parent subtree.
|
|
87
|
+
const parentIndex = updatedTreeData.findIndex((node) => node.key === sourceId);
|
|
88
|
+
if (parentIndex !== -1) {
|
|
89
|
+
insertionIndex = parentIndex + 1;
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const newNodeBase = {
|
|
95
|
+
hierarchy: newNodeHierarchy,
|
|
96
|
+
parentId: newNodeParentId,
|
|
97
|
+
sourceId: effectiveSourceNode?.key ?? sourceId ?? payloadSourceId ?? 'new-node',
|
|
98
|
+
isNewNode: true,
|
|
99
|
+
key: 'new-node',
|
|
100
|
+
value,
|
|
101
|
+
error,
|
|
102
|
+
label,
|
|
103
|
+
type,
|
|
104
|
+
options: convertedOptions,
|
|
105
|
+
selectedOption: convertedSelectedOption,
|
|
106
|
+
confirmIconTooltip,
|
|
107
|
+
cancelIconTooltip,
|
|
108
|
+
};
|
|
109
|
+
switch (action) {
|
|
110
|
+
case 'addAbove':
|
|
111
|
+
updatedTreeData.splice(sourceIndex, 0, newNodeBase);
|
|
112
|
+
break;
|
|
113
|
+
case 'addBelow':
|
|
114
|
+
updatedTreeData.splice(sourceIndex + 1, 0, newNodeBase);
|
|
115
|
+
break;
|
|
116
|
+
case 'addInside':
|
|
117
|
+
updatedTreeData.splice(Math.max(0, insertionIndex), 0, newNodeBase);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
return updatedTreeData;
|
|
121
|
+
};
|
|
122
|
+
const prepareTreeRows = (treeData, rootNode) => {
|
|
123
|
+
if (!treeData?.length)
|
|
124
|
+
return [];
|
|
125
|
+
const nodeById = new Map();
|
|
126
|
+
const childrenByParent = new Map();
|
|
127
|
+
const siblingIndex = new Map();
|
|
128
|
+
const loadedCountsByParent = new Map();
|
|
129
|
+
if (rootNode && rootNode.key) {
|
|
130
|
+
nodeById.set(rootNode.key, rootNode);
|
|
131
|
+
}
|
|
132
|
+
treeData.forEach((node) => {
|
|
133
|
+
nodeById.set(node.key, node);
|
|
134
|
+
const parentKey = node.parentId ?? ROOT_PARENT_ID;
|
|
135
|
+
if (!childrenByParent.has(parentKey)) {
|
|
136
|
+
childrenByParent.set(parentKey, []);
|
|
137
|
+
loadedCountsByParent.set(parentKey, { container: 0, resource: 0 });
|
|
138
|
+
}
|
|
139
|
+
childrenByParent.get(parentKey)?.push(node);
|
|
140
|
+
const counts = loadedCountsByParent.get(parentKey);
|
|
141
|
+
if (counts) {
|
|
142
|
+
if (node.container) {
|
|
143
|
+
counts.container++;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
counts.resource++;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
childrenByParent.forEach((children) => {
|
|
151
|
+
children.forEach((child, index) => {
|
|
152
|
+
siblingIndex.set(child.key, index);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
const hasNextSibling = (node) => {
|
|
156
|
+
const parentKey = node.parentId ?? ROOT_PARENT_ID;
|
|
157
|
+
const siblings = childrenByParent.get(parentKey);
|
|
158
|
+
if (!siblings || siblings.length === 0)
|
|
159
|
+
return false;
|
|
160
|
+
const index = siblingIndex.get(node.key) ?? 0;
|
|
161
|
+
if (index < siblings.length - 1)
|
|
162
|
+
return true;
|
|
163
|
+
const parent = nodeById.get(parentKey);
|
|
164
|
+
const loadedCounts = loadedCountsByParent.get(parentKey);
|
|
165
|
+
if (parent && loadedCounts) {
|
|
166
|
+
const siblingContainerResources = siblings
|
|
167
|
+
.filter((node) => node.container)
|
|
168
|
+
.reduce((sum, node) => sum + (node.totalResourceCount ?? 0), 0);
|
|
169
|
+
const siblingDirectResourcesCount = siblings.filter((node) => !node.container).length;
|
|
170
|
+
const calculatedDirectResources = Math.max(0, (parent.totalResourceCount ?? 0) -
|
|
171
|
+
(siblingContainerResources + siblingDirectResourcesCount));
|
|
172
|
+
if (node.container) {
|
|
173
|
+
const hasMoreContainers = loadedCounts.container < (parent.subContainerCount ?? 0);
|
|
174
|
+
const hasResourcesFollowing = calculatedDirectResources > 0;
|
|
175
|
+
return hasMoreContainers || hasResourcesFollowing;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return loadedCounts.resource < calculatedDirectResources;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
182
|
+
};
|
|
183
|
+
const buildParentSiblings = (node) => {
|
|
184
|
+
const hierarchy = node.hierarchy ?? 0;
|
|
185
|
+
if (hierarchy <= 0)
|
|
186
|
+
return [];
|
|
187
|
+
const path = [];
|
|
188
|
+
let current = node;
|
|
189
|
+
while (current) {
|
|
190
|
+
path.unshift(current);
|
|
191
|
+
if (!current.parentId)
|
|
192
|
+
break;
|
|
193
|
+
const parent = nodeById.get(current.parentId);
|
|
194
|
+
if (!parent)
|
|
195
|
+
break;
|
|
196
|
+
current = parent;
|
|
197
|
+
}
|
|
198
|
+
const flags = path.map((ancestor) => hasNextSibling(ancestor));
|
|
199
|
+
if (flags.length === hierarchy)
|
|
200
|
+
return flags;
|
|
201
|
+
if (flags.length > hierarchy)
|
|
202
|
+
return flags.slice(flags.length - hierarchy);
|
|
203
|
+
const padding = new Array(hierarchy - flags.length).fill(false);
|
|
204
|
+
return padding.concat(flags);
|
|
205
|
+
};
|
|
206
|
+
const resolveSelectedStatus = (node) => {
|
|
207
|
+
if (node.selectedStatus !== undefined)
|
|
208
|
+
return node.selectedStatus;
|
|
209
|
+
let current = node;
|
|
210
|
+
while (current?.parentId) {
|
|
211
|
+
const parent = nodeById.get(current.parentId);
|
|
212
|
+
if (!parent)
|
|
213
|
+
break;
|
|
214
|
+
if (parent.selectedStatus === 'completely')
|
|
215
|
+
return 'completely';
|
|
216
|
+
if (parent.selectedStatus === 'none')
|
|
217
|
+
return 'none';
|
|
218
|
+
current = parent;
|
|
219
|
+
}
|
|
220
|
+
if (rootNode?.selectedStatus === 'completely')
|
|
221
|
+
return 'completely';
|
|
222
|
+
if (rootNode?.selectedStatus === 'none')
|
|
223
|
+
return 'none';
|
|
224
|
+
return node.selectedStatus;
|
|
225
|
+
};
|
|
226
|
+
return treeData.map((node) => {
|
|
227
|
+
const nodeWithSiblings = node;
|
|
228
|
+
const finalParentSiblings = nodeWithSiblings.parentSiblings &&
|
|
229
|
+
nodeWithSiblings.parentSiblings.length > 0
|
|
230
|
+
? nodeWithSiblings.parentSiblings
|
|
231
|
+
: buildParentSiblings(node);
|
|
232
|
+
return {
|
|
233
|
+
...node,
|
|
234
|
+
lastChild: !hasNextSibling(node),
|
|
235
|
+
parentSiblings: finalParentSiblings,
|
|
236
|
+
selectedStatus: resolveSelectedStatus(node),
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
const TableTreeFn = forwardRef(({ treeData, columnsData, selected = [], select = null, onChange = () => { }, onClick = () => { }, onExpand = () => { }, loadMore = () => { }, tableBorder, height = 'calc(100vh - 134px)', newNode, onAddConfirm = () => { }, onAddCancel = () => { }, handleEditFieldError, loading = false, rootNode, pagination = true, selectedNode, tableHeaderBgColor = 'var(--border-color)', hideOnDisable = false, freezeColumns, scriptLengthTruncate = 25, addModuleInputWidth = 150, addModuleSelectWidth, onScroll, onScrollEnd, disableEditLabelConfirmIcon = false, transparentHeader = false, navigateTreeNode = null, handleRemoveNavigateTreeNode = () => { }, scrollThreshold = 128, showHeader = true, onHover, onHoverOut, rootNameWidth, rootNameHoveredWidth, }, ref) => {
|
|
11
241
|
const [expanding, setExpanding] = useState(null);
|
|
12
|
-
const [scrollDirection, setScrollDirection] = useState(null);
|
|
13
|
-
const [
|
|
14
|
-
const [
|
|
15
|
-
const [maintainScrollPosition, setMaintainScrollPosition] = useState(null);
|
|
242
|
+
const [scrollDirection, setScrollDirection] = useState(null);
|
|
243
|
+
const [virtualRange, setVirtualRange] = useState({ start: 0, end: 20 });
|
|
244
|
+
const [newNodeEditable, setNewNodeEditable] = useState(false);
|
|
16
245
|
const containerRef = useRef(null);
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
246
|
+
const headerRef = useRef(null);
|
|
247
|
+
const headerHeightRef = useRef(0);
|
|
248
|
+
const loadingRef = useRef(loading);
|
|
249
|
+
const scrollDirectionRef = useRef(null);
|
|
250
|
+
const scrollRafRef = useRef(null);
|
|
251
|
+
const scrollPositionRef = useRef({ lastScrollTop: 0 });
|
|
252
|
+
const previousFirstKeyRef = useRef(null);
|
|
253
|
+
const suppressScrollCancelUntilRef = useRef(0);
|
|
254
|
+
const debouncedScrollEndRef = useRef(null);
|
|
255
|
+
const expandTargetRef = useRef(null);
|
|
256
|
+
const expandingFallbackTimerRef = useRef(null);
|
|
257
|
+
const navigateAttemptsRef = useRef({ key: null, attempts: 0 });
|
|
258
|
+
const navigateClearTimerRef = useRef(null);
|
|
259
|
+
const isDropdownOpenRef = useRef(false);
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
const observer = new MutationObserver(() => {
|
|
262
|
+
const dropdowns = document.querySelectorAll('.ff-option-card');
|
|
263
|
+
isDropdownOpenRef.current = dropdowns.length > 0;
|
|
264
|
+
});
|
|
265
|
+
observer.observe(document.body, {
|
|
266
|
+
childList: true,
|
|
267
|
+
subtree: true,
|
|
268
|
+
});
|
|
269
|
+
return () => observer.disconnect();
|
|
270
|
+
}, []);
|
|
271
|
+
const handleHover = useCallback((rowId) => {
|
|
272
|
+
if (!isDropdownOpenRef.current) {
|
|
273
|
+
onHover?.(rowId);
|
|
274
|
+
}
|
|
275
|
+
}, [onHover]);
|
|
276
|
+
const handleHoverOut = useCallback((rowId) => {
|
|
277
|
+
if (!isDropdownOpenRef.current) {
|
|
278
|
+
onHoverOut?.(rowId);
|
|
279
|
+
}
|
|
280
|
+
}, [onHoverOut]);
|
|
281
|
+
const getWidthInfo = (width, defaultWidth) => {
|
|
282
|
+
const w = width ?? defaultWidth;
|
|
283
|
+
const str = String(w);
|
|
284
|
+
if (str.endsWith('%')) {
|
|
285
|
+
return { value: parseFloat(str), unit: '%' };
|
|
286
|
+
}
|
|
287
|
+
return { value: parseFloat(str) || 0, unit: 'px' };
|
|
288
|
+
};
|
|
289
|
+
const columnMeta = useMemo(() => {
|
|
290
|
+
let stickyLeftPx = 0;
|
|
291
|
+
let stickyLeftPct = 0;
|
|
292
|
+
return columnsData.map((col, index) => {
|
|
293
|
+
const { value, unit } = getWidthInfo(col.width, DEFAULT_COLUMN_WIDTH);
|
|
294
|
+
const sticky = !!freezeColumns && index < freezeColumns;
|
|
295
|
+
const widthCss = unit === '%' ? `${value}%` : `${value}px`;
|
|
296
|
+
const leftCss = `calc(${stickyLeftPx}px + ${stickyLeftPct}%)`;
|
|
297
|
+
const meta = {
|
|
298
|
+
width: widthCss,
|
|
299
|
+
sticky,
|
|
300
|
+
left: leftCss,
|
|
301
|
+
zIndex: sticky ? 100 + (freezeColumns ?? 0) - index : 1,
|
|
302
|
+
};
|
|
303
|
+
if (sticky) {
|
|
304
|
+
if (unit === '%') {
|
|
305
|
+
stickyLeftPct += value;
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
stickyLeftPx += value;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return meta;
|
|
312
|
+
});
|
|
313
|
+
}, [columnsData, freezeColumns]);
|
|
314
|
+
const totalWidth = useMemo(() => {
|
|
315
|
+
let totalPx = 0;
|
|
316
|
+
let totalPct = 0;
|
|
317
|
+
columnsData.forEach((col) => {
|
|
318
|
+
const { value, unit } = getWidthInfo(col.width, DEFAULT_COLUMN_WIDTH);
|
|
319
|
+
if (unit === '%') {
|
|
320
|
+
totalPct += value;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
totalPx += value;
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
return `calc(${totalPx}px + ${totalPct}%)`;
|
|
327
|
+
}, [columnsData]);
|
|
328
|
+
const frozenColumnWidth = useMemo(() => {
|
|
329
|
+
if (!freezeColumns)
|
|
330
|
+
return '0px';
|
|
331
|
+
let totalPx = 0;
|
|
332
|
+
let totalPct = 0;
|
|
333
|
+
const frozenCols = columnMeta.slice(0, freezeColumns);
|
|
334
|
+
frozenCols.forEach((col) => {
|
|
335
|
+
const val = parseFloat(col.width) || 0;
|
|
336
|
+
if (col.width.endsWith('%')) {
|
|
337
|
+
totalPct += val;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
totalPx += val;
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
return `calc(${totalPx}px + ${totalPct}%)`;
|
|
344
|
+
}, [columnMeta, freezeColumns]);
|
|
345
|
+
const treeDataWithNewNode = useMemo(() => insertNewNode(treeData, newNode, rootNode?.node), [treeData, newNode, rootNode]);
|
|
346
|
+
const preparedRows = useMemo(() => prepareTreeRows(treeDataWithNewNode, rootNode?.node), [treeDataWithNewNode, rootNode?.node]);
|
|
347
|
+
const visiblePreparedRows = useMemo(() => preparedRows.filter((node) => !node.hide), [preparedRows]);
|
|
348
|
+
const preparedRowsByKey = useMemo(() => {
|
|
349
|
+
const map = new Map();
|
|
350
|
+
preparedRows.forEach((node) => map.set(node.key, node));
|
|
351
|
+
return map;
|
|
352
|
+
}, [preparedRows]);
|
|
353
|
+
const keyIndexMap = useMemo(() => {
|
|
354
|
+
const map = new Map();
|
|
355
|
+
visiblePreparedRows.forEach((node, index) => map.set(node.key, index));
|
|
356
|
+
return map;
|
|
357
|
+
}, [visiblePreparedRows]);
|
|
358
|
+
const clearExpanding = useCallback((targetKey) => {
|
|
359
|
+
setExpanding((current) => {
|
|
360
|
+
if (!current)
|
|
361
|
+
return current;
|
|
362
|
+
if (targetKey && current !== targetKey)
|
|
363
|
+
return current;
|
|
364
|
+
return null;
|
|
365
|
+
});
|
|
366
|
+
if (!targetKey || expandTargetRef.current?.key === targetKey) {
|
|
367
|
+
expandTargetRef.current = null;
|
|
368
|
+
}
|
|
369
|
+
if (expandingFallbackTimerRef.current) {
|
|
370
|
+
clearTimeout(expandingFallbackTimerRef.current);
|
|
371
|
+
expandingFallbackTimerRef.current = null;
|
|
372
|
+
}
|
|
373
|
+
}, []);
|
|
374
|
+
useEffect(() => {
|
|
375
|
+
loadingRef.current = loading;
|
|
376
|
+
}, [loading]);
|
|
377
|
+
useEffect(() => {
|
|
378
|
+
scrollDirectionRef.current = scrollDirection;
|
|
379
|
+
}, [scrollDirection]);
|
|
380
|
+
const updateScrollDirection = useCallback((direction) => {
|
|
381
|
+
scrollDirectionRef.current = direction;
|
|
382
|
+
setScrollDirection(direction);
|
|
383
|
+
}, []);
|
|
384
|
+
const updateVirtualRange = useCallback(() => {
|
|
385
|
+
const container = containerRef.current;
|
|
386
|
+
if (!container)
|
|
387
|
+
return;
|
|
388
|
+
const headerHeight = headerHeightRef.current || 0;
|
|
389
|
+
const rowScrollTop = Math.max(0, container.scrollTop - headerHeight);
|
|
390
|
+
const viewportHeight = container.clientHeight - headerHeight;
|
|
391
|
+
let start = Math.floor(rowScrollTop / ROW_HEIGHT) - OVERSCAN;
|
|
392
|
+
let end = Math.ceil((rowScrollTop + viewportHeight) / ROW_HEIGHT) + OVERSCAN;
|
|
393
|
+
start = Math.max(0, start);
|
|
394
|
+
end = Math.min(visiblePreparedRows.length, end);
|
|
395
|
+
setVirtualRange((prev) => {
|
|
396
|
+
if (prev.start === start && prev.end === end)
|
|
397
|
+
return prev;
|
|
398
|
+
return { start, end };
|
|
399
|
+
});
|
|
400
|
+
}, [visiblePreparedRows.length]);
|
|
401
|
+
const scheduleRangeUpdate = useCallback(() => {
|
|
402
|
+
if (scrollRafRef.current !== null)
|
|
27
403
|
return;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}, [
|
|
33
|
-
|
|
34
|
-
|
|
404
|
+
scrollRafRef.current = requestAnimationFrame(() => {
|
|
405
|
+
scrollRafRef.current = null;
|
|
406
|
+
updateVirtualRange();
|
|
407
|
+
});
|
|
408
|
+
}, [updateVirtualRange]);
|
|
409
|
+
// Handle scroll position safety when searching/filtering
|
|
410
|
+
useLayoutEffect(() => {
|
|
411
|
+
const container = containerRef.current;
|
|
412
|
+
if (!container)
|
|
35
413
|
return;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
414
|
+
const totalContentHeight = visiblePreparedRows.length * ROW_HEIGHT;
|
|
415
|
+
const maxScrollTop = Math.max(0, totalContentHeight - (container.clientHeight - headerHeightRef.current));
|
|
416
|
+
if (scrollPositionRef.current.lastScrollTop > maxScrollTop &&
|
|
417
|
+
visiblePreparedRows.length > 0) {
|
|
418
|
+
container.scrollTop = 0;
|
|
419
|
+
scrollPositionRef.current.lastScrollTop = 0;
|
|
420
|
+
}
|
|
421
|
+
updateVirtualRange();
|
|
422
|
+
}, [visiblePreparedRows.length, updateVirtualRange]);
|
|
40
423
|
const handleScroll = useCallback(() => {
|
|
41
424
|
const container = containerRef.current;
|
|
42
|
-
if (!container
|
|
425
|
+
if (!container)
|
|
43
426
|
return;
|
|
44
|
-
const now = Date.now();
|
|
45
427
|
const currentScrollTop = container.scrollTop;
|
|
46
|
-
const scrollHeight = container.scrollHeight;
|
|
47
|
-
const clientHeight = container.clientHeight;
|
|
48
|
-
// Scroll direction calculation
|
|
49
428
|
const direction = currentScrollTop > scrollPositionRef.current.lastScrollTop
|
|
50
429
|
? 'down'
|
|
51
430
|
: 'up';
|
|
52
|
-
scrollPositionRef.current =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
431
|
+
scrollPositionRef.current.lastScrollTop = currentScrollTop;
|
|
432
|
+
scheduleRangeUpdate();
|
|
433
|
+
onScroll?.();
|
|
434
|
+
debouncedScrollEndRef.current?.();
|
|
435
|
+
if (!pagination ||
|
|
436
|
+
loading ||
|
|
437
|
+
scrollDirectionRef.current ||
|
|
438
|
+
checkEmpty(treeData))
|
|
439
|
+
return;
|
|
440
|
+
const scrollHeight = container.scrollHeight;
|
|
441
|
+
const clientHeight = container.clientHeight;
|
|
62
442
|
const nearBottom = scrollHeight - (currentScrollTop + clientHeight) < scrollThreshold;
|
|
63
|
-
const nearTop = currentScrollTop < scrollThreshold;
|
|
443
|
+
const nearTop = currentScrollTop < scrollThreshold + headerHeightRef.current;
|
|
64
444
|
if (direction === 'down' &&
|
|
65
445
|
nearBottom &&
|
|
66
|
-
!
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
nearTop &&
|
|
75
|
-
!loading &&
|
|
76
|
-
!scrollDirection &&
|
|
77
|
-
treeData[0]?.lastResource !== true) {
|
|
78
|
-
scrollDebounceRef.current = setTimeout(() => {
|
|
79
|
-
loadMoreAbove();
|
|
80
|
-
}, 150);
|
|
81
|
-
}
|
|
82
|
-
// Scroll Restoration After Loading Above
|
|
83
|
-
if (!loading &&
|
|
84
|
-
scrollDirection === 'above' &&
|
|
85
|
-
previousTreeDataRef.current.length > 0 &&
|
|
86
|
-
prevScrollTop !== null) {
|
|
87
|
-
const previousTreeData = previousTreeDataRef.current;
|
|
88
|
-
let addedRowsCount = 0;
|
|
89
|
-
for (let i = 0; i < treeData.length; i++) {
|
|
90
|
-
if (previousTreeData[0] === treeData[i])
|
|
91
|
-
break;
|
|
92
|
-
addedRowsCount++;
|
|
93
|
-
}
|
|
94
|
-
let retries = 0;
|
|
95
|
-
const maxRetries = 30;
|
|
96
|
-
// this function will try to restore the scroll position after loading more data specially when loading more data above
|
|
97
|
-
const tryRestoreScroll = () => {
|
|
98
|
-
const allRows = Array.from(container.querySelectorAll('.ff-table-tree-row'));
|
|
99
|
-
let totalAddedHeight = 0;
|
|
100
|
-
for (let i = 0; i < addedRowsCount; i++) {
|
|
101
|
-
const height = allRows[i]?.getBoundingClientRect().height || 0;
|
|
102
|
-
totalAddedHeight += height;
|
|
103
|
-
}
|
|
104
|
-
const canScroll = container.scrollHeight > container.clientHeight;
|
|
105
|
-
const validHeights = totalAddedHeight > 0;
|
|
106
|
-
if (validHeights && canScroll) {
|
|
107
|
-
container.scrollTop = prevScrollTop + totalAddedHeight;
|
|
108
|
-
previousTreeDataRef.current = treeData;
|
|
109
|
-
}
|
|
110
|
-
else if (retries < maxRetries) {
|
|
111
|
-
retries++;
|
|
112
|
-
requestAnimationFrame(tryRestoreScroll);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
previousTreeDataRef.current = treeData;
|
|
116
|
-
console.warn('Failed to restore scroll position after max retries');
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
requestAnimationFrame(tryRestoreScroll);
|
|
446
|
+
!treeData[treeData.length - 1]?.lastResource) {
|
|
447
|
+
updateScrollDirection('below');
|
|
448
|
+
loadMore('below');
|
|
449
|
+
}
|
|
450
|
+
if (direction === 'up' && nearTop && !treeData[0]?.lastResource) {
|
|
451
|
+
updateScrollDirection('above');
|
|
452
|
+
previousFirstKeyRef.current = treeData[0]?.key ?? null;
|
|
453
|
+
loadMore('above');
|
|
120
454
|
}
|
|
121
455
|
}, [
|
|
456
|
+
treeData,
|
|
457
|
+
pagination,
|
|
122
458
|
loading,
|
|
123
459
|
scrollDirection,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
loadMoreBelow,
|
|
127
|
-
prevScrollTop,
|
|
460
|
+
scrollThreshold,
|
|
461
|
+
scheduleRangeUpdate,
|
|
128
462
|
onScroll,
|
|
463
|
+
loadMore,
|
|
464
|
+
updateScrollDirection,
|
|
129
465
|
]);
|
|
130
|
-
// Attach scroll event listener for updated first node when we scroll
|
|
131
466
|
useEffect(() => {
|
|
132
|
-
|
|
133
|
-
|
|
467
|
+
if (loading || !pagination || checkEmpty(treeData))
|
|
468
|
+
return;
|
|
469
|
+
const firstNode = treeData[0];
|
|
470
|
+
const hasMoreAbove = !firstNode?.lastResource;
|
|
471
|
+
const { totalSubContainerCount = 0, totalResourceCount = 0 } = rootNode?.node || {};
|
|
472
|
+
const totalItems = totalSubContainerCount + totalResourceCount;
|
|
473
|
+
const isListTooShort = visiblePreparedRows.length < 10 &&
|
|
474
|
+
visiblePreparedRows.length < totalItems;
|
|
475
|
+
if (hasMoreAbove && isListTooShort) {
|
|
476
|
+
previousFirstKeyRef.current = firstNode?.key ?? null;
|
|
477
|
+
updateScrollDirection('above');
|
|
478
|
+
loadMore('above');
|
|
479
|
+
}
|
|
480
|
+
}, [
|
|
481
|
+
loading,
|
|
482
|
+
pagination,
|
|
483
|
+
treeData,
|
|
484
|
+
visiblePreparedRows.length,
|
|
485
|
+
rootNode,
|
|
486
|
+
loadMore,
|
|
487
|
+
updateScrollDirection,
|
|
488
|
+
]);
|
|
489
|
+
useLayoutEffect(() => {
|
|
490
|
+
if (!loading && scrollDirection === 'above') {
|
|
491
|
+
const container = containerRef.current;
|
|
492
|
+
const previousKey = previousFirstKeyRef.current;
|
|
493
|
+
if (container && previousKey) {
|
|
494
|
+
const newIndex = keyIndexMap.get(previousKey);
|
|
495
|
+
if (newIndex !== undefined && newIndex > 0) {
|
|
496
|
+
container.scrollTop += newIndex * ROW_HEIGHT;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
previousFirstKeyRef.current = null;
|
|
500
|
+
updateScrollDirection(null);
|
|
501
|
+
}
|
|
502
|
+
else if (!loading && scrollDirection === 'below') {
|
|
503
|
+
updateScrollDirection(null);
|
|
504
|
+
}
|
|
505
|
+
}, [loading, scrollDirection, keyIndexMap, updateScrollDirection]);
|
|
506
|
+
useEffect(() => {
|
|
507
|
+
const container = containerRef.current;
|
|
508
|
+
if (!container)
|
|
134
509
|
return;
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
510
|
+
const handleWheelAtTop = (event) => {
|
|
511
|
+
if (event.deltaY >= 0)
|
|
512
|
+
return;
|
|
513
|
+
if (!pagination || checkEmpty(treeData) || loadingRef.current)
|
|
514
|
+
return;
|
|
515
|
+
if (scrollDirectionRef.current)
|
|
516
|
+
return;
|
|
517
|
+
if (container.scrollTop > 1 || treeData[0]?.lastResource)
|
|
518
|
+
return;
|
|
519
|
+
previousFirstKeyRef.current = treeData[0]?.key ?? null;
|
|
520
|
+
updateScrollDirection('above');
|
|
521
|
+
loadMore('above');
|
|
141
522
|
};
|
|
142
|
-
|
|
523
|
+
container.addEventListener('wheel', handleWheelAtTop, { passive: true });
|
|
143
524
|
return () => {
|
|
144
|
-
|
|
145
|
-
debouncedOnScrollEnd.cancel();
|
|
525
|
+
container.removeEventListener('wheel', handleWheelAtTop);
|
|
146
526
|
};
|
|
147
|
-
}, [
|
|
527
|
+
}, [pagination, treeData, loadMore, updateScrollDirection]);
|
|
148
528
|
useEffect(() => {
|
|
529
|
+
const container = containerRef.current;
|
|
530
|
+
if (!container)
|
|
531
|
+
return;
|
|
532
|
+
debouncedScrollEndRef.current = onScrollEnd
|
|
533
|
+
? debounce(() => {
|
|
534
|
+
onScrollEnd?.();
|
|
535
|
+
}, 150)
|
|
536
|
+
: null;
|
|
537
|
+
container.addEventListener('scroll', handleScroll, { passive: true });
|
|
149
538
|
return () => {
|
|
150
|
-
|
|
151
|
-
|
|
539
|
+
container.removeEventListener('scroll', handleScroll);
|
|
540
|
+
debouncedScrollEndRef.current?.cancel();
|
|
541
|
+
};
|
|
542
|
+
}, [handleScroll, onScrollEnd]);
|
|
543
|
+
useEffect(() => {
|
|
544
|
+
const container = containerRef.current;
|
|
545
|
+
if (!container)
|
|
546
|
+
return;
|
|
547
|
+
const handleScrollCapture = (event) => {
|
|
548
|
+
if (Date.now() < suppressScrollCancelUntilRef.current) {
|
|
549
|
+
event.stopImmediatePropagation();
|
|
152
550
|
}
|
|
153
551
|
};
|
|
552
|
+
container.addEventListener('scroll', handleScrollCapture, {
|
|
553
|
+
passive: true,
|
|
554
|
+
capture: true,
|
|
555
|
+
});
|
|
556
|
+
return () => {
|
|
557
|
+
container.removeEventListener('scroll', handleScrollCapture, true);
|
|
558
|
+
};
|
|
154
559
|
}, []);
|
|
155
|
-
|
|
560
|
+
useEffect(() => {
|
|
561
|
+
const headerNode = headerRef.current;
|
|
562
|
+
if (!headerNode)
|
|
563
|
+
return;
|
|
564
|
+
const updateHeight = () => {
|
|
565
|
+
headerHeightRef.current = headerNode.getBoundingClientRect().height;
|
|
566
|
+
updateVirtualRange();
|
|
567
|
+
};
|
|
568
|
+
const resizeObserver = new ResizeObserver(updateHeight);
|
|
569
|
+
resizeObserver.observe(headerNode);
|
|
570
|
+
return () => resizeObserver.disconnect();
|
|
571
|
+
}, [updateVirtualRange]);
|
|
156
572
|
useLayoutEffect(() => {
|
|
157
|
-
if (!
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
573
|
+
if (!newNode || !containerRef.current)
|
|
574
|
+
return;
|
|
575
|
+
const container = containerRef.current;
|
|
576
|
+
const newNodeIndex = keyIndexMap.get('new-node');
|
|
577
|
+
if (newNodeIndex === undefined)
|
|
578
|
+
return;
|
|
579
|
+
const headerHeight = headerHeightRef.current || 0;
|
|
580
|
+
const viewportHeight = container.clientHeight - headerHeight;
|
|
581
|
+
if (viewportHeight <= 0)
|
|
582
|
+
return;
|
|
583
|
+
const rowTop = newNodeIndex * ROW_HEIGHT;
|
|
584
|
+
const rowBottom = rowTop + ROW_HEIGHT;
|
|
585
|
+
const rowScrollTop = Math.max(0, container.scrollTop - headerHeight);
|
|
586
|
+
const viewTop = rowScrollTop;
|
|
587
|
+
const viewBottom = rowScrollTop + viewportHeight;
|
|
588
|
+
let nextRowScrollTop = rowScrollTop;
|
|
589
|
+
if (rowTop < viewTop) {
|
|
590
|
+
nextRowScrollTop = rowTop;
|
|
171
591
|
}
|
|
172
|
-
else if (
|
|
173
|
-
|
|
592
|
+
else if (rowBottom > viewBottom) {
|
|
593
|
+
nextRowScrollTop = Math.max(0, rowBottom - viewportHeight);
|
|
174
594
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const node = document.getElementById(navigateTreeNode);
|
|
180
|
-
const container = containerRef.current;
|
|
181
|
-
if (node && container) {
|
|
182
|
-
// Store current scroll position
|
|
183
|
-
setMaintainScrollPosition(container.scrollTop);
|
|
184
|
-
// Calculate scroll position
|
|
185
|
-
const nodeRect = node.getBoundingClientRect();
|
|
186
|
-
const containerRect = container.getBoundingClientRect();
|
|
187
|
-
const scrollTop = container.scrollTop;
|
|
188
|
-
const nodeTop = nodeRect.top - containerRect.top + scrollTop;
|
|
189
|
-
const containerHeight = containerRect.height;
|
|
190
|
-
// Scroll to center the node
|
|
191
|
-
container.scrollTo({
|
|
192
|
-
top: nodeTop - containerHeight / 2 + nodeRect.height / 2,
|
|
193
|
-
behavior: 'smooth',
|
|
194
|
-
});
|
|
195
|
-
}
|
|
595
|
+
if (nextRowScrollTop !== rowScrollTop) {
|
|
596
|
+
suppressScrollCancelUntilRef.current = Date.now() + 300;
|
|
597
|
+
container.scrollTop = nextRowScrollTop + headerHeight;
|
|
598
|
+
updateVirtualRange();
|
|
196
599
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
|
|
600
|
+
const rafId = requestAnimationFrame(() => {
|
|
601
|
+
setNewNodeEditable(true);
|
|
602
|
+
});
|
|
603
|
+
return () => cancelAnimationFrame(rafId);
|
|
604
|
+
}, [newNode, keyIndexMap, updateVirtualRange]);
|
|
202
605
|
useEffect(() => {
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
setMaintainScrollPosition(null);
|
|
606
|
+
if (!newNode) {
|
|
607
|
+
setNewNodeEditable(false);
|
|
206
608
|
}
|
|
207
|
-
}, [
|
|
208
|
-
|
|
609
|
+
}, [newNode]);
|
|
610
|
+
useLayoutEffect(() => {
|
|
611
|
+
if (!expanding || loading)
|
|
612
|
+
return;
|
|
613
|
+
const expected = expandTargetRef.current;
|
|
614
|
+
if (!expected || expected.key !== expanding) {
|
|
615
|
+
const rafId = requestAnimationFrame(() => {
|
|
616
|
+
clearExpanding(expanding);
|
|
617
|
+
});
|
|
618
|
+
return () => cancelAnimationFrame(rafId);
|
|
619
|
+
}
|
|
620
|
+
const updatedNode = preparedRowsByKey.get(expected.key);
|
|
621
|
+
if (!updatedNode) {
|
|
622
|
+
const rafId = requestAnimationFrame(() => {
|
|
623
|
+
clearExpanding(expected.key);
|
|
624
|
+
});
|
|
625
|
+
return () => cancelAnimationFrame(rafId);
|
|
626
|
+
}
|
|
627
|
+
if (Boolean(updatedNode.expanded) !== expected.expanded)
|
|
628
|
+
return;
|
|
629
|
+
const rafId = requestAnimationFrame(() => {
|
|
630
|
+
clearExpanding(expected.key);
|
|
631
|
+
});
|
|
632
|
+
return () => cancelAnimationFrame(rafId);
|
|
633
|
+
}, [preparedRowsByKey, expanding, loading, clearExpanding]);
|
|
209
634
|
useEffect(() => {
|
|
635
|
+
if (navigateAttemptsRef.current.key !== navigateTreeNode) {
|
|
636
|
+
navigateAttemptsRef.current = {
|
|
637
|
+
key: navigateTreeNode,
|
|
638
|
+
attempts: 0,
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
if (!navigateTreeNode && navigateClearTimerRef.current) {
|
|
642
|
+
clearTimeout(navigateClearTimerRef.current);
|
|
643
|
+
navigateClearTimerRef.current = null;
|
|
644
|
+
}
|
|
645
|
+
}, [navigateTreeNode]);
|
|
646
|
+
useLayoutEffect(() => {
|
|
647
|
+
if (!navigateTreeNode || newNode)
|
|
648
|
+
return;
|
|
210
649
|
const container = containerRef.current;
|
|
211
|
-
if (!container
|
|
650
|
+
if (!container)
|
|
212
651
|
return;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
652
|
+
const rowIndex = keyIndexMap.get(navigateTreeNode);
|
|
653
|
+
if (rowIndex !== undefined) {
|
|
654
|
+
navigateAttemptsRef.current = {
|
|
655
|
+
key: navigateTreeNode,
|
|
656
|
+
attempts: 0,
|
|
657
|
+
};
|
|
658
|
+
const headerHeight = headerHeightRef.current || 0;
|
|
659
|
+
const viewportHeight = Math.max(ROW_HEIGHT, container.clientHeight - headerHeight);
|
|
660
|
+
const rowCenter = rowIndex * ROW_HEIGHT + ROW_HEIGHT / 2;
|
|
661
|
+
const targetTop = Math.max(0, rowCenter - viewportHeight / 2) + headerHeight;
|
|
662
|
+
suppressScrollCancelUntilRef.current = Date.now() + 400;
|
|
663
|
+
container.scrollTo({
|
|
664
|
+
top: targetTop,
|
|
665
|
+
behavior: 'smooth',
|
|
666
|
+
});
|
|
667
|
+
scheduleRangeUpdate();
|
|
668
|
+
if (navigateClearTimerRef.current) {
|
|
669
|
+
clearTimeout(navigateClearTimerRef.current);
|
|
220
670
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (treeData.length > 0) {
|
|
226
|
-
previousTreeDataRef.current = treeData;
|
|
671
|
+
navigateClearTimerRef.current = setTimeout(() => {
|
|
672
|
+
handleRemoveNavigateTreeNode?.();
|
|
673
|
+
}, 350);
|
|
674
|
+
return;
|
|
227
675
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
676
|
+
if (loading || scrollDirection)
|
|
677
|
+
return;
|
|
678
|
+
const retryState = navigateAttemptsRef.current;
|
|
679
|
+
if (retryState.key !== navigateTreeNode) {
|
|
680
|
+
retryState.key = navigateTreeNode;
|
|
681
|
+
retryState.attempts = 0;
|
|
232
682
|
}
|
|
233
|
-
|
|
683
|
+
retryState.attempts += 1;
|
|
684
|
+
if (retryState.attempts > 30) {
|
|
685
|
+
handleRemoveNavigateTreeNode?.();
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (pagination && treeData[0]?.lastResource !== true) {
|
|
689
|
+
previousFirstKeyRef.current = null;
|
|
690
|
+
updateScrollDirection('above');
|
|
691
|
+
loadMore('above');
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
if (retryState.attempts > 2) {
|
|
695
|
+
handleRemoveNavigateTreeNode?.();
|
|
696
|
+
}
|
|
697
|
+
}, [
|
|
698
|
+
navigateTreeNode,
|
|
699
|
+
newNode,
|
|
700
|
+
keyIndexMap,
|
|
701
|
+
loading,
|
|
702
|
+
scrollDirection,
|
|
703
|
+
pagination,
|
|
704
|
+
treeData,
|
|
705
|
+
loadMore,
|
|
706
|
+
scheduleRangeUpdate,
|
|
707
|
+
handleRemoveNavigateTreeNode,
|
|
708
|
+
updateScrollDirection,
|
|
709
|
+
]);
|
|
234
710
|
const handleToggleExpand = useCallback((node) => {
|
|
235
711
|
if (expanding)
|
|
236
712
|
return;
|
|
713
|
+
const nextExpandedState = !node?.expanded;
|
|
237
714
|
setExpanding(node.key);
|
|
715
|
+
expandTargetRef.current = {
|
|
716
|
+
key: node.key,
|
|
717
|
+
expanded: nextExpandedState,
|
|
718
|
+
};
|
|
719
|
+
if (expandingFallbackTimerRef.current) {
|
|
720
|
+
clearTimeout(expandingFallbackTimerRef.current);
|
|
721
|
+
}
|
|
722
|
+
const fallbackStartedAt = Date.now();
|
|
723
|
+
const MAX_FALLBACK_WAIT_MS = 2000;
|
|
724
|
+
const FALLBACK_CHECK_INTERVAL_MS = 1000;
|
|
725
|
+
const ensureExpandCleanup = () => {
|
|
726
|
+
if (expandTargetRef.current?.key !== node.key)
|
|
727
|
+
return;
|
|
728
|
+
const isStillLoading = loadingRef.current;
|
|
729
|
+
const didTimeout = Date.now() - fallbackStartedAt >= MAX_FALLBACK_WAIT_MS;
|
|
730
|
+
if (isStillLoading && !didTimeout) {
|
|
731
|
+
expandingFallbackTimerRef.current = setTimeout(ensureExpandCleanup, FALLBACK_CHECK_INTERVAL_MS);
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
clearExpanding(node.key);
|
|
735
|
+
};
|
|
736
|
+
expandingFallbackTimerRef.current = setTimeout(ensureExpandCleanup, FALLBACK_CHECK_INTERVAL_MS);
|
|
238
737
|
onExpand?.(node);
|
|
239
|
-
}, [onExpand,
|
|
738
|
+
}, [expanding, onExpand, clearExpanding]);
|
|
240
739
|
const handleCheckBoxChange = useCallback((e, node) => {
|
|
241
740
|
if (expanding)
|
|
242
741
|
return;
|
|
@@ -247,69 +746,32 @@ showHeader = true, }, ref) => {
|
|
|
247
746
|
return;
|
|
248
747
|
onClick?.(e, node);
|
|
249
748
|
}, [onClick, expanding]);
|
|
250
|
-
const DEFAULT_COLUMN_WIDTH = 400;
|
|
251
|
-
const calculateFrozenWidth = (columnData, freezeColumns) => {
|
|
252
|
-
return columnData
|
|
253
|
-
.slice(0, freezeColumns)
|
|
254
|
-
.reduce((acc, col) => acc + parseInt(col.width || `${DEFAULT_COLUMN_WIDTH}`, 10), 0);
|
|
255
|
-
};
|
|
256
|
-
let frozenWidth;
|
|
257
|
-
if (freezeColumns) {
|
|
258
|
-
frozenWidth = calculateFrozenWidth(columnsData, freezeColumns);
|
|
259
|
-
}
|
|
260
|
-
// half visible, click on upward arrow functionality, page auto scrolling
|
|
261
749
|
useEffect(() => {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
newNode.sourceId === treeData[0]?.key) {
|
|
267
|
-
container.scrollTo({ top: 0, behavior: 'smooth' });
|
|
268
|
-
}
|
|
269
|
-
else if (newNode.action === 'addAbove' &&
|
|
270
|
-
newNode.sourceId === newNode.firstNodeKey) {
|
|
271
|
-
const newScrollTop = container.scrollTop - 64;
|
|
272
|
-
container.scrollTo({ top: newScrollTop, behavior: 'smooth' });
|
|
273
|
-
}
|
|
274
|
-
}, [newNode]);
|
|
275
|
-
useLayoutEffect(() => {
|
|
276
|
-
if (!navigateTreeNode)
|
|
277
|
-
return;
|
|
278
|
-
const container = containerRef.current;
|
|
279
|
-
if (!container)
|
|
280
|
-
return;
|
|
281
|
-
let retryCount = 0;
|
|
282
|
-
const maxRetries = 30;
|
|
283
|
-
const scrollToNode = () => {
|
|
284
|
-
const element = document.getElementById(navigateTreeNode);
|
|
285
|
-
if (element) {
|
|
286
|
-
setTimeout(() => {
|
|
287
|
-
element.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
288
|
-
handleRemoveNavigateTreeNode();
|
|
289
|
-
}, 200);
|
|
750
|
+
return () => {
|
|
751
|
+
if (scrollRafRef.current !== null) {
|
|
752
|
+
cancelAnimationFrame(scrollRafRef.current);
|
|
753
|
+
scrollRafRef.current = null;
|
|
290
754
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
retryCount++;
|
|
297
|
-
requestAnimationFrame(scrollToNode);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
handleRemoveNavigateTreeNode();
|
|
301
|
-
}
|
|
755
|
+
if (expandingFallbackTimerRef.current) {
|
|
756
|
+
clearTimeout(expandingFallbackTimerRef.current);
|
|
757
|
+
}
|
|
758
|
+
if (navigateClearTimerRef.current) {
|
|
759
|
+
clearTimeout(navigateClearTimerRef.current);
|
|
302
760
|
}
|
|
303
761
|
};
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
'--
|
|
309
|
-
|
|
310
|
-
: '0px',
|
|
762
|
+
}, []);
|
|
763
|
+
const totalHeight = visiblePreparedRows.length * ROW_HEIGHT;
|
|
764
|
+
const visibleRows = visiblePreparedRows.slice(virtualRange.start, virtualRange.end);
|
|
765
|
+
return (_jsx("div", { className: "tree-table-wrapper-container table-tree-fn", children: _jsx("div", { className: "tree-table-fn-wrap", ref: ref, children: _jsx("div", { className: `table-fn-scrollable ${visiblePreparedRows.length ? '' : 'table-fn-empty'}`, ref: containerRef, style: {
|
|
766
|
+
'--table-height': visiblePreparedRows.length ? height : 'auto',
|
|
767
|
+
'--frozen-column-width': frozenColumnWidth,
|
|
311
768
|
border: tableBorder,
|
|
312
|
-
}, children: _jsxs("
|
|
769
|
+
}, children: _jsxs("div", { className: "tree-table-fn", style: { width: totalWidth }, children: [_jsx("div", { ref: headerRef, style: { position: 'sticky', top: 0, zIndex: 98 }, children: _jsx(TableHead, { columnsData: columnsData, columnMeta: columnMeta, totalWidth: totalWidth, rootNode: rootNode, onCheckBoxChange: handleCheckBoxChange, selected: selected, selectedNode: selectedNode, tableHeaderBgColor: tableHeaderBgColor, hideOnDisable: hideOnDisable, transparentHeader: transparentHeader, scriptLengthTruncate: scriptLengthTruncate, showHeader: showHeader, rootNameWidth: rootNameWidth, rootNameHoveredWidth: rootNameHoveredWidth }) }), _jsx(TableBody, { flattenedTreeData: visibleRows, columnsData: columnsData, columnMeta: columnMeta, totalWidth: totalWidth, rowHeight: ROW_HEIGHT, startIndex: virtualRange.start, totalHeight: totalHeight, selected: selected, select: select, onRowClick: handleRowClick, onToggleExpand: handleToggleExpand, onCheckBoxChange: handleCheckBoxChange, onAddConfirm: onAddConfirm, onAddCancel: onAddCancel, handleEditFieldError: handleEditFieldError, expanding: expanding, selectedNode: selectedNode, hideOnDisable: hideOnDisable, scriptLengthTruncate: scriptLengthTruncate, addModuleInputWidth: addModuleInputWidth, addModuleSelectWidth: addModuleSelectWidth, disableEditLabelConfirmIcon: disableEditLabelConfirmIcon, isEditable: newNode ? newNodeEditable : undefined, setIsEditable: newNode
|
|
770
|
+
? (id) => {
|
|
771
|
+
setNewNodeEditable(Boolean(id));
|
|
772
|
+
}
|
|
773
|
+
: undefined, onHover: handleHover, onHoverOut: handleHoverOut })] }) }) }) }));
|
|
313
774
|
});
|
|
775
|
+
TableTreeFn.displayName = 'TableTreeFn';
|
|
314
776
|
export default TableTreeFn;
|
|
315
777
|
//# sourceMappingURL=TableTreeFn.js.map
|