pixel-priya 1.2.82 → 1.2.84
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/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/constants.js +55 -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 +68 -5
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/ActiveCell.js.map +1 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.js +5 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.js.map +1 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/actions.d.ts +8 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/actions.js +7 -0
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/actions.js.map +1 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/reducer.js +18 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/reducer.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 +4 -0
- package/lib/components/Icon/iconList.js.map +1 -1
- package/lib/components/MachineInputField/MachineInputField.js +1 -0
- package/lib/components/MachineInputField/MachineInputField.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/MultiSelect/Dropdown.js +2 -1
- package/lib/components/MultiSelect/Dropdown.js.map +1 -1
- package/lib/components/PopUpModal/PopUpModal.js +1 -1
- package/lib/components/PopUpModal/PopUpModal.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/components/Dropdown.js +68 -31
- package/lib/components/Select/components/Dropdown.js.map +1 -1
- package/lib/components/SequentialConnectingBranch/types.d.ts +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/StatusButton.d.ts +1 -1
- package/lib/components/StatusButton/StatusButton.js +3 -2
- package/lib/components/StatusButton/StatusButton.js.map +1 -1
- package/lib/components/StatusButton/types.d.ts +2 -1
- package/lib/components/StepsLandingTable/Components/StepGroupAccordions.js +8 -5
- package/lib/components/StepsLandingTable/Components/StepGroupAccordions.js.map +1 -1
- package/lib/components/StepsLandingTable/Components/StepResultStats.js +4 -1
- package/lib/components/StepsLandingTable/Components/StepResultStats.js.map +1 -1
- package/lib/components/StepsLandingTable/Components/StepTableMainRow.js +10 -4
- 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 +19 -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 +674 -248
- 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 +36 -7
- package/lib/index.d.ts +14 -6
- package/lib/index.js +9 -9
- 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 +1 -2
|
@@ -1,242 +1,705 @@
|
|
|
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, }, 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 scrollRafRef = useRef(null);
|
|
250
|
+
const scrollPositionRef = useRef({ lastScrollTop: 0 });
|
|
251
|
+
const previousFirstKeyRef = useRef(null);
|
|
252
|
+
const suppressScrollCancelUntilRef = useRef(0);
|
|
253
|
+
const debouncedScrollEndRef = useRef(null);
|
|
254
|
+
const expandTargetRef = useRef(null);
|
|
255
|
+
const expandingFallbackTimerRef = useRef(null);
|
|
256
|
+
const navigateAttemptsRef = useRef({ key: null, attempts: 0 });
|
|
257
|
+
const navigateClearTimerRef = useRef(null);
|
|
258
|
+
const isDropdownOpenRef = useRef(false);
|
|
259
|
+
useEffect(() => {
|
|
260
|
+
const observer = new MutationObserver(() => {
|
|
261
|
+
const dropdowns = document.querySelectorAll('.ff-option-card');
|
|
262
|
+
isDropdownOpenRef.current = dropdowns.length > 0;
|
|
263
|
+
});
|
|
264
|
+
observer.observe(document.body, {
|
|
265
|
+
childList: true,
|
|
266
|
+
subtree: true,
|
|
267
|
+
});
|
|
268
|
+
return () => observer.disconnect();
|
|
269
|
+
}, []);
|
|
270
|
+
const handleHover = useCallback((rowId) => {
|
|
271
|
+
if (!isDropdownOpenRef.current) {
|
|
272
|
+
onHover?.(rowId);
|
|
273
|
+
}
|
|
274
|
+
}, [onHover]);
|
|
275
|
+
const handleHoverOut = useCallback((rowId) => {
|
|
276
|
+
if (!isDropdownOpenRef.current) {
|
|
277
|
+
onHoverOut?.(rowId);
|
|
278
|
+
}
|
|
279
|
+
}, [onHoverOut]);
|
|
280
|
+
const getWidthInfo = (width, defaultWidth) => {
|
|
281
|
+
const w = width ?? defaultWidth;
|
|
282
|
+
const str = String(w);
|
|
283
|
+
if (str.endsWith('%')) {
|
|
284
|
+
return { value: parseFloat(str), unit: '%' };
|
|
285
|
+
}
|
|
286
|
+
return { value: parseFloat(str) || 0, unit: 'px' };
|
|
287
|
+
};
|
|
288
|
+
const columnMeta = useMemo(() => {
|
|
289
|
+
let stickyLeftPx = 0;
|
|
290
|
+
let stickyLeftPct = 0;
|
|
291
|
+
return columnsData.map((col, index) => {
|
|
292
|
+
const { value, unit } = getWidthInfo(col.width, DEFAULT_COLUMN_WIDTH);
|
|
293
|
+
const sticky = !!freezeColumns && index < freezeColumns;
|
|
294
|
+
const widthCss = unit === '%' ? `${value}%` : `${value}px`;
|
|
295
|
+
const leftCss = `calc(${stickyLeftPx}px + ${stickyLeftPct}%)`;
|
|
296
|
+
const meta = {
|
|
297
|
+
width: widthCss,
|
|
298
|
+
sticky,
|
|
299
|
+
left: leftCss,
|
|
300
|
+
zIndex: sticky ? 100 + (freezeColumns ?? 0) - index : 1,
|
|
301
|
+
};
|
|
302
|
+
if (sticky) {
|
|
303
|
+
if (unit === '%') {
|
|
304
|
+
stickyLeftPct += value;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
stickyLeftPx += value;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return meta;
|
|
311
|
+
});
|
|
312
|
+
}, [columnsData, freezeColumns]);
|
|
313
|
+
const totalWidth = useMemo(() => {
|
|
314
|
+
let totalPx = 0;
|
|
315
|
+
let totalPct = 0;
|
|
316
|
+
columnsData.forEach((col) => {
|
|
317
|
+
const { value, unit } = getWidthInfo(col.width, DEFAULT_COLUMN_WIDTH);
|
|
318
|
+
if (unit === '%') {
|
|
319
|
+
totalPct += value;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
totalPx += value;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
return `calc(${totalPx}px + ${totalPct}%)`;
|
|
326
|
+
}, [columnsData]);
|
|
327
|
+
const frozenColumnWidth = useMemo(() => {
|
|
328
|
+
if (!freezeColumns)
|
|
329
|
+
return '0px';
|
|
330
|
+
let totalPx = 0;
|
|
331
|
+
let totalPct = 0;
|
|
332
|
+
const frozenCols = columnMeta.slice(0, freezeColumns);
|
|
333
|
+
frozenCols.forEach((col) => {
|
|
334
|
+
const val = parseFloat(col.width) || 0;
|
|
335
|
+
if (col.width.endsWith('%')) {
|
|
336
|
+
totalPct += val;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
totalPx += val;
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
return `calc(${totalPx}px + ${totalPct}%)`;
|
|
343
|
+
}, [columnMeta, freezeColumns]);
|
|
344
|
+
const treeDataWithNewNode = useMemo(() => insertNewNode(treeData, newNode, rootNode?.node), [treeData, newNode, rootNode]);
|
|
345
|
+
const preparedRows = useMemo(() => prepareTreeRows(treeDataWithNewNode, rootNode?.node), [treeDataWithNewNode, rootNode?.node]);
|
|
346
|
+
const visiblePreparedRows = useMemo(() => preparedRows.filter((node) => !node.hide), [preparedRows]);
|
|
347
|
+
const preparedRowsByKey = useMemo(() => {
|
|
348
|
+
const map = new Map();
|
|
349
|
+
preparedRows.forEach((node) => map.set(node.key, node));
|
|
350
|
+
return map;
|
|
351
|
+
}, [preparedRows]);
|
|
352
|
+
const keyIndexMap = useMemo(() => {
|
|
353
|
+
const map = new Map();
|
|
354
|
+
visiblePreparedRows.forEach((node, index) => map.set(node.key, index));
|
|
355
|
+
return map;
|
|
356
|
+
}, [visiblePreparedRows]);
|
|
357
|
+
const clearExpanding = useCallback((targetKey) => {
|
|
358
|
+
setExpanding((current) => {
|
|
359
|
+
if (!current)
|
|
360
|
+
return current;
|
|
361
|
+
if (targetKey && current !== targetKey)
|
|
362
|
+
return current;
|
|
363
|
+
return null;
|
|
364
|
+
});
|
|
365
|
+
if (!targetKey || expandTargetRef.current?.key === targetKey) {
|
|
366
|
+
expandTargetRef.current = null;
|
|
367
|
+
}
|
|
368
|
+
if (expandingFallbackTimerRef.current) {
|
|
369
|
+
clearTimeout(expandingFallbackTimerRef.current);
|
|
370
|
+
expandingFallbackTimerRef.current = null;
|
|
371
|
+
}
|
|
372
|
+
}, []);
|
|
373
|
+
useEffect(() => {
|
|
374
|
+
loadingRef.current = loading;
|
|
375
|
+
}, [loading]);
|
|
376
|
+
const updateVirtualRange = useCallback(() => {
|
|
377
|
+
const container = containerRef.current;
|
|
378
|
+
if (!container)
|
|
379
|
+
return;
|
|
380
|
+
const headerHeight = headerHeightRef.current || 0;
|
|
381
|
+
const rowScrollTop = Math.max(0, container.scrollTop - headerHeight);
|
|
382
|
+
const viewportHeight = container.clientHeight - headerHeight;
|
|
383
|
+
let start = Math.floor(rowScrollTop / ROW_HEIGHT) - OVERSCAN;
|
|
384
|
+
let end = Math.ceil((rowScrollTop + viewportHeight) / ROW_HEIGHT) + OVERSCAN;
|
|
385
|
+
start = Math.max(0, start);
|
|
386
|
+
end = Math.min(visiblePreparedRows.length, end);
|
|
387
|
+
setVirtualRange((prev) => {
|
|
388
|
+
if (prev.start === start && prev.end === end)
|
|
389
|
+
return prev;
|
|
390
|
+
return { start, end };
|
|
391
|
+
});
|
|
392
|
+
}, [visiblePreparedRows.length]);
|
|
393
|
+
const scheduleRangeUpdate = useCallback(() => {
|
|
394
|
+
if (scrollRafRef.current !== null)
|
|
27
395
|
return;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}, [
|
|
33
|
-
|
|
34
|
-
|
|
396
|
+
scrollRafRef.current = requestAnimationFrame(() => {
|
|
397
|
+
scrollRafRef.current = null;
|
|
398
|
+
updateVirtualRange();
|
|
399
|
+
});
|
|
400
|
+
}, [updateVirtualRange]);
|
|
401
|
+
// Handle scroll position safety when searching/filtering
|
|
402
|
+
useLayoutEffect(() => {
|
|
403
|
+
const container = containerRef.current;
|
|
404
|
+
if (!container)
|
|
35
405
|
return;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
406
|
+
const totalContentHeight = visiblePreparedRows.length * ROW_HEIGHT;
|
|
407
|
+
const maxScrollTop = Math.max(0, totalContentHeight - (container.clientHeight - headerHeightRef.current));
|
|
408
|
+
if (scrollPositionRef.current.lastScrollTop > maxScrollTop &&
|
|
409
|
+
visiblePreparedRows.length > 0) {
|
|
410
|
+
container.scrollTop = 0;
|
|
411
|
+
scrollPositionRef.current.lastScrollTop = 0;
|
|
412
|
+
}
|
|
413
|
+
updateVirtualRange();
|
|
414
|
+
}, [visiblePreparedRows.length, updateVirtualRange]);
|
|
40
415
|
const handleScroll = useCallback(() => {
|
|
41
416
|
const container = containerRef.current;
|
|
42
|
-
if (!container
|
|
417
|
+
if (!container)
|
|
43
418
|
return;
|
|
44
|
-
const now = Date.now();
|
|
45
419
|
const currentScrollTop = container.scrollTop;
|
|
46
|
-
const scrollHeight = container.scrollHeight;
|
|
47
|
-
const clientHeight = container.clientHeight;
|
|
48
|
-
// Scroll direction calculation
|
|
49
420
|
const direction = currentScrollTop > scrollPositionRef.current.lastScrollTop
|
|
50
421
|
? 'down'
|
|
51
422
|
: 'up';
|
|
52
|
-
scrollPositionRef.current =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
// Infinite Scroll
|
|
423
|
+
scrollPositionRef.current.lastScrollTop = currentScrollTop;
|
|
424
|
+
scheduleRangeUpdate();
|
|
425
|
+
onScroll?.();
|
|
426
|
+
debouncedScrollEndRef.current?.();
|
|
427
|
+
if (!pagination || loading || scrollDirection || checkEmpty(treeData))
|
|
428
|
+
return;
|
|
429
|
+
const scrollHeight = container.scrollHeight;
|
|
430
|
+
const clientHeight = container.clientHeight;
|
|
62
431
|
const nearBottom = scrollHeight - (currentScrollTop + clientHeight) < scrollThreshold;
|
|
63
|
-
const nearTop = currentScrollTop < scrollThreshold;
|
|
432
|
+
const nearTop = currentScrollTop < scrollThreshold + headerHeightRef.current;
|
|
64
433
|
if (direction === 'down' &&
|
|
65
434
|
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);
|
|
435
|
+
!treeData[treeData.length - 1]?.lastResource) {
|
|
436
|
+
setScrollDirection('below');
|
|
437
|
+
loadMore('below');
|
|
438
|
+
}
|
|
439
|
+
if (direction === 'up' && nearTop && !treeData[0]?.lastResource) {
|
|
440
|
+
setScrollDirection('above');
|
|
441
|
+
previousFirstKeyRef.current = treeData[0]?.key ?? null;
|
|
442
|
+
loadMore('above');
|
|
120
443
|
}
|
|
121
444
|
}, [
|
|
445
|
+
treeData,
|
|
446
|
+
pagination,
|
|
122
447
|
loading,
|
|
123
448
|
scrollDirection,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
loadMoreBelow,
|
|
127
|
-
prevScrollTop,
|
|
449
|
+
scrollThreshold,
|
|
450
|
+
scheduleRangeUpdate,
|
|
128
451
|
onScroll,
|
|
452
|
+
loadMore,
|
|
129
453
|
]);
|
|
130
|
-
// Attach scroll event listener for updated first node when we scroll
|
|
131
454
|
useEffect(() => {
|
|
132
|
-
|
|
133
|
-
if (!scrollDiv)
|
|
455
|
+
if (loading || !pagination || checkEmpty(treeData))
|
|
134
456
|
return;
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}, []);
|
|
155
|
-
// Handle scroll position restoration after loading
|
|
457
|
+
const firstNode = treeData[0];
|
|
458
|
+
const hasMoreAbove = !firstNode?.lastResource;
|
|
459
|
+
const { totalSubContainerCount = 0, totalResourceCount = 0 } = rootNode?.node || {};
|
|
460
|
+
const totalItems = totalSubContainerCount + totalResourceCount;
|
|
461
|
+
const isListTooShort = visiblePreparedRows.length < 10 &&
|
|
462
|
+
visiblePreparedRows.length < totalItems;
|
|
463
|
+
if (hasMoreAbove && isListTooShort) {
|
|
464
|
+
previousFirstKeyRef.current = firstNode?.key ?? null;
|
|
465
|
+
setScrollDirection('above');
|
|
466
|
+
loadMore('above');
|
|
467
|
+
}
|
|
468
|
+
}, [
|
|
469
|
+
loading,
|
|
470
|
+
pagination,
|
|
471
|
+
treeData,
|
|
472
|
+
visiblePreparedRows.length,
|
|
473
|
+
rootNode,
|
|
474
|
+
loadMore,
|
|
475
|
+
]);
|
|
156
476
|
useLayoutEffect(() => {
|
|
157
|
-
if (!loading &&
|
|
158
|
-
scrollDirection === 'above' &&
|
|
159
|
-
prevScrollTop !== null &&
|
|
160
|
-
prevScrollHeight !== null) {
|
|
477
|
+
if (!loading && scrollDirection === 'above') {
|
|
161
478
|
const container = containerRef.current;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
479
|
+
const previousKey = previousFirstKeyRef.current;
|
|
480
|
+
if (container && previousKey) {
|
|
481
|
+
const newIndex = keyIndexMap.get(previousKey);
|
|
482
|
+
if (newIndex !== undefined && newIndex > 0) {
|
|
483
|
+
container.scrollTop += newIndex * ROW_HEIGHT;
|
|
484
|
+
}
|
|
167
485
|
}
|
|
486
|
+
previousFirstKeyRef.current = null;
|
|
168
487
|
setScrollDirection(null);
|
|
169
|
-
setPrevScrollTop(null);
|
|
170
|
-
setPrevScrollHeight(null);
|
|
171
488
|
}
|
|
172
|
-
else if (!loading) {
|
|
489
|
+
else if (!loading && scrollDirection === 'below') {
|
|
173
490
|
setScrollDirection(null);
|
|
174
491
|
}
|
|
175
|
-
}, [loading, scrollDirection,
|
|
176
|
-
// Handle navigation to specific nodes
|
|
492
|
+
}, [loading, scrollDirection, keyIndexMap]);
|
|
177
493
|
useEffect(() => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
}
|
|
196
|
-
}
|
|
494
|
+
const container = containerRef.current;
|
|
495
|
+
if (!container)
|
|
496
|
+
return;
|
|
497
|
+
debouncedScrollEndRef.current = onScrollEnd
|
|
498
|
+
? debounce(() => {
|
|
499
|
+
onScrollEnd?.();
|
|
500
|
+
}, 150)
|
|
501
|
+
: null;
|
|
502
|
+
container.addEventListener('scroll', handleScroll, { passive: true });
|
|
197
503
|
return () => {
|
|
198
|
-
|
|
504
|
+
container.removeEventListener('scroll', handleScroll);
|
|
505
|
+
debouncedScrollEndRef.current?.cancel();
|
|
199
506
|
};
|
|
200
|
-
}, [
|
|
201
|
-
// Restore scroll position after navigation
|
|
202
|
-
useEffect(() => {
|
|
203
|
-
if (maintainScrollPosition !== null && !loading && containerRef.current) {
|
|
204
|
-
containerRef.current.scrollTop = maintainScrollPosition;
|
|
205
|
-
setMaintainScrollPosition(null);
|
|
206
|
-
}
|
|
207
|
-
}, [maintainScrollPosition, loading]);
|
|
208
|
-
// Setup scroll listener
|
|
507
|
+
}, [handleScroll, onScrollEnd]);
|
|
209
508
|
useEffect(() => {
|
|
210
509
|
const container = containerRef.current;
|
|
211
|
-
if (!container
|
|
510
|
+
if (!container)
|
|
212
511
|
return;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return () => {
|
|
217
|
-
container.removeEventListener('scroll', handleScroll);
|
|
218
|
-
if (scrollDebounceRef.current) {
|
|
219
|
-
clearTimeout(scrollDebounceRef.current);
|
|
512
|
+
const handleScrollCapture = (event) => {
|
|
513
|
+
if (Date.now() < suppressScrollCancelUntilRef.current) {
|
|
514
|
+
event.stopImmediatePropagation();
|
|
220
515
|
}
|
|
221
516
|
};
|
|
222
|
-
|
|
223
|
-
|
|
517
|
+
container.addEventListener('scroll', handleScrollCapture, {
|
|
518
|
+
passive: true,
|
|
519
|
+
capture: true,
|
|
520
|
+
});
|
|
521
|
+
return () => {
|
|
522
|
+
container.removeEventListener('scroll', handleScrollCapture, true);
|
|
523
|
+
};
|
|
524
|
+
}, []);
|
|
224
525
|
useEffect(() => {
|
|
225
|
-
|
|
226
|
-
|
|
526
|
+
const headerNode = headerRef.current;
|
|
527
|
+
if (!headerNode)
|
|
528
|
+
return;
|
|
529
|
+
const updateHeight = () => {
|
|
530
|
+
headerHeightRef.current = headerNode.getBoundingClientRect().height;
|
|
531
|
+
updateVirtualRange();
|
|
532
|
+
};
|
|
533
|
+
const resizeObserver = new ResizeObserver(updateHeight);
|
|
534
|
+
resizeObserver.observe(headerNode);
|
|
535
|
+
return () => resizeObserver.disconnect();
|
|
536
|
+
}, [updateVirtualRange]);
|
|
537
|
+
useLayoutEffect(() => {
|
|
538
|
+
if (!newNode || !containerRef.current)
|
|
539
|
+
return;
|
|
540
|
+
const container = containerRef.current;
|
|
541
|
+
const newNodeIndex = keyIndexMap.get('new-node');
|
|
542
|
+
if (newNodeIndex === undefined)
|
|
543
|
+
return;
|
|
544
|
+
const headerHeight = headerHeightRef.current || 0;
|
|
545
|
+
const viewportHeight = container.clientHeight - headerHeight;
|
|
546
|
+
if (viewportHeight <= 0)
|
|
547
|
+
return;
|
|
548
|
+
const rowTop = newNodeIndex * ROW_HEIGHT;
|
|
549
|
+
const rowBottom = rowTop + ROW_HEIGHT;
|
|
550
|
+
const rowScrollTop = Math.max(0, container.scrollTop - headerHeight);
|
|
551
|
+
const viewTop = rowScrollTop;
|
|
552
|
+
const viewBottom = rowScrollTop + viewportHeight;
|
|
553
|
+
let nextRowScrollTop = rowScrollTop;
|
|
554
|
+
if (rowTop < viewTop) {
|
|
555
|
+
nextRowScrollTop = rowTop;
|
|
227
556
|
}
|
|
228
|
-
|
|
557
|
+
else if (rowBottom > viewBottom) {
|
|
558
|
+
nextRowScrollTop = Math.max(0, rowBottom - viewportHeight);
|
|
559
|
+
}
|
|
560
|
+
if (nextRowScrollTop !== rowScrollTop) {
|
|
561
|
+
suppressScrollCancelUntilRef.current = Date.now() + 300;
|
|
562
|
+
container.scrollTop = nextRowScrollTop + headerHeight;
|
|
563
|
+
updateVirtualRange();
|
|
564
|
+
}
|
|
565
|
+
const rafId = requestAnimationFrame(() => {
|
|
566
|
+
setNewNodeEditable(true);
|
|
567
|
+
});
|
|
568
|
+
return () => cancelAnimationFrame(rafId);
|
|
569
|
+
}, [newNode, keyIndexMap, updateVirtualRange]);
|
|
229
570
|
useEffect(() => {
|
|
230
|
-
if (!
|
|
231
|
-
|
|
571
|
+
if (!newNode) {
|
|
572
|
+
setNewNodeEditable(false);
|
|
232
573
|
}
|
|
233
|
-
}, [
|
|
574
|
+
}, [newNode]);
|
|
575
|
+
useLayoutEffect(() => {
|
|
576
|
+
if (!expanding || loading)
|
|
577
|
+
return;
|
|
578
|
+
const expected = expandTargetRef.current;
|
|
579
|
+
if (!expected || expected.key !== expanding) {
|
|
580
|
+
const rafId = requestAnimationFrame(() => {
|
|
581
|
+
clearExpanding(expanding);
|
|
582
|
+
});
|
|
583
|
+
return () => cancelAnimationFrame(rafId);
|
|
584
|
+
}
|
|
585
|
+
const updatedNode = preparedRowsByKey.get(expected.key);
|
|
586
|
+
if (!updatedNode) {
|
|
587
|
+
const rafId = requestAnimationFrame(() => {
|
|
588
|
+
clearExpanding(expected.key);
|
|
589
|
+
});
|
|
590
|
+
return () => cancelAnimationFrame(rafId);
|
|
591
|
+
}
|
|
592
|
+
if (Boolean(updatedNode.expanded) !== expected.expanded)
|
|
593
|
+
return;
|
|
594
|
+
const rafId = requestAnimationFrame(() => {
|
|
595
|
+
clearExpanding(expected.key);
|
|
596
|
+
});
|
|
597
|
+
return () => cancelAnimationFrame(rafId);
|
|
598
|
+
}, [preparedRowsByKey, expanding, loading, clearExpanding]);
|
|
599
|
+
useEffect(() => {
|
|
600
|
+
if (navigateAttemptsRef.current.key !== navigateTreeNode) {
|
|
601
|
+
navigateAttemptsRef.current = {
|
|
602
|
+
key: navigateTreeNode,
|
|
603
|
+
attempts: 0,
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
if (!navigateTreeNode && navigateClearTimerRef.current) {
|
|
607
|
+
clearTimeout(navigateClearTimerRef.current);
|
|
608
|
+
navigateClearTimerRef.current = null;
|
|
609
|
+
}
|
|
610
|
+
}, [navigateTreeNode]);
|
|
611
|
+
useLayoutEffect(() => {
|
|
612
|
+
if (!navigateTreeNode || newNode)
|
|
613
|
+
return;
|
|
614
|
+
const container = containerRef.current;
|
|
615
|
+
if (!container)
|
|
616
|
+
return;
|
|
617
|
+
const rowIndex = keyIndexMap.get(navigateTreeNode);
|
|
618
|
+
if (rowIndex !== undefined) {
|
|
619
|
+
navigateAttemptsRef.current = {
|
|
620
|
+
key: navigateTreeNode,
|
|
621
|
+
attempts: 0,
|
|
622
|
+
};
|
|
623
|
+
const headerHeight = headerHeightRef.current || 0;
|
|
624
|
+
const viewportHeight = Math.max(ROW_HEIGHT, container.clientHeight - headerHeight);
|
|
625
|
+
const rowCenter = rowIndex * ROW_HEIGHT + ROW_HEIGHT / 2;
|
|
626
|
+
const targetTop = Math.max(0, rowCenter - viewportHeight / 2) + headerHeight;
|
|
627
|
+
suppressScrollCancelUntilRef.current = Date.now() + 400;
|
|
628
|
+
container.scrollTo({
|
|
629
|
+
top: targetTop,
|
|
630
|
+
behavior: 'smooth',
|
|
631
|
+
});
|
|
632
|
+
scheduleRangeUpdate();
|
|
633
|
+
if (navigateClearTimerRef.current) {
|
|
634
|
+
clearTimeout(navigateClearTimerRef.current);
|
|
635
|
+
}
|
|
636
|
+
navigateClearTimerRef.current = setTimeout(() => {
|
|
637
|
+
handleRemoveNavigateTreeNode?.();
|
|
638
|
+
}, 350);
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
if (loading || scrollDirection)
|
|
642
|
+
return;
|
|
643
|
+
const retryState = navigateAttemptsRef.current;
|
|
644
|
+
if (retryState.key !== navigateTreeNode) {
|
|
645
|
+
retryState.key = navigateTreeNode;
|
|
646
|
+
retryState.attempts = 0;
|
|
647
|
+
}
|
|
648
|
+
retryState.attempts += 1;
|
|
649
|
+
if (retryState.attempts > 30) {
|
|
650
|
+
handleRemoveNavigateTreeNode?.();
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (pagination && treeData[0]?.lastResource !== true) {
|
|
654
|
+
previousFirstKeyRef.current = null;
|
|
655
|
+
setScrollDirection('above');
|
|
656
|
+
loadMore('above');
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
if (retryState.attempts > 2) {
|
|
660
|
+
handleRemoveNavigateTreeNode?.();
|
|
661
|
+
}
|
|
662
|
+
}, [
|
|
663
|
+
navigateTreeNode,
|
|
664
|
+
newNode,
|
|
665
|
+
keyIndexMap,
|
|
666
|
+
loading,
|
|
667
|
+
scrollDirection,
|
|
668
|
+
pagination,
|
|
669
|
+
treeData,
|
|
670
|
+
loadMore,
|
|
671
|
+
scheduleRangeUpdate,
|
|
672
|
+
handleRemoveNavigateTreeNode,
|
|
673
|
+
]);
|
|
234
674
|
const handleToggleExpand = useCallback((node) => {
|
|
235
675
|
if (expanding)
|
|
236
676
|
return;
|
|
677
|
+
const nextExpandedState = !node?.expanded;
|
|
237
678
|
setExpanding(node.key);
|
|
679
|
+
expandTargetRef.current = {
|
|
680
|
+
key: node.key,
|
|
681
|
+
expanded: nextExpandedState,
|
|
682
|
+
};
|
|
683
|
+
if (expandingFallbackTimerRef.current) {
|
|
684
|
+
clearTimeout(expandingFallbackTimerRef.current);
|
|
685
|
+
}
|
|
686
|
+
const fallbackStartedAt = Date.now();
|
|
687
|
+
const MAX_FALLBACK_WAIT_MS = 2000;
|
|
688
|
+
const FALLBACK_CHECK_INTERVAL_MS = 1000;
|
|
689
|
+
const ensureExpandCleanup = () => {
|
|
690
|
+
if (expandTargetRef.current?.key !== node.key)
|
|
691
|
+
return;
|
|
692
|
+
const isStillLoading = loadingRef.current;
|
|
693
|
+
const didTimeout = Date.now() - fallbackStartedAt >= MAX_FALLBACK_WAIT_MS;
|
|
694
|
+
if (isStillLoading && !didTimeout) {
|
|
695
|
+
expandingFallbackTimerRef.current = setTimeout(ensureExpandCleanup, FALLBACK_CHECK_INTERVAL_MS);
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
clearExpanding(node.key);
|
|
699
|
+
};
|
|
700
|
+
expandingFallbackTimerRef.current = setTimeout(ensureExpandCleanup, FALLBACK_CHECK_INTERVAL_MS);
|
|
238
701
|
onExpand?.(node);
|
|
239
|
-
}, [onExpand,
|
|
702
|
+
}, [expanding, onExpand, clearExpanding]);
|
|
240
703
|
const handleCheckBoxChange = useCallback((e, node) => {
|
|
241
704
|
if (expanding)
|
|
242
705
|
return;
|
|
@@ -247,69 +710,32 @@ showHeader = true, }, ref) => {
|
|
|
247
710
|
return;
|
|
248
711
|
onClick?.(e, node);
|
|
249
712
|
}, [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
713
|
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);
|
|
714
|
+
return () => {
|
|
715
|
+
if (scrollRafRef.current !== null) {
|
|
716
|
+
cancelAnimationFrame(scrollRafRef.current);
|
|
717
|
+
scrollRafRef.current = null;
|
|
290
718
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
retryCount++;
|
|
297
|
-
requestAnimationFrame(scrollToNode);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
handleRemoveNavigateTreeNode();
|
|
301
|
-
}
|
|
719
|
+
if (expandingFallbackTimerRef.current) {
|
|
720
|
+
clearTimeout(expandingFallbackTimerRef.current);
|
|
721
|
+
}
|
|
722
|
+
if (navigateClearTimerRef.current) {
|
|
723
|
+
clearTimeout(navigateClearTimerRef.current);
|
|
302
724
|
}
|
|
303
725
|
};
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
'--
|
|
309
|
-
|
|
310
|
-
: '0px',
|
|
726
|
+
}, []);
|
|
727
|
+
const totalHeight = visiblePreparedRows.length * ROW_HEIGHT;
|
|
728
|
+
const visibleRows = visiblePreparedRows.slice(virtualRange.start, virtualRange.end);
|
|
729
|
+
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: {
|
|
730
|
+
'--table-height': visiblePreparedRows.length ? height : 'auto',
|
|
731
|
+
'--frozen-column-width': frozenColumnWidth,
|
|
311
732
|
border: tableBorder,
|
|
312
|
-
}, children: _jsxs("
|
|
733
|
+
}, 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 }) }), _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
|
|
734
|
+
? (id) => {
|
|
735
|
+
setNewNodeEditable(Boolean(id));
|
|
736
|
+
}
|
|
737
|
+
: undefined, onHover: handleHover, onHoverOut: handleHoverOut })] }) }) }) }));
|
|
313
738
|
});
|
|
739
|
+
TableTreeFn.displayName = 'TableTreeFn';
|
|
314
740
|
export default TableTreeFn;
|
|
315
741
|
//# sourceMappingURL=TableTreeFn.js.map
|