@elliemae/ds-treeview 2.2.0-alpha.4 → 3.0.0-next.2
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/cjs/TreeView.js +27 -49
- package/cjs/TreeViewContext.js +37 -61
- package/cjs/config/cssClassesConstants.js +13 -41
- package/cjs/config/useTreeview.js +78 -116
- package/cjs/hoc/DnDTreeContext.js +18 -0
- package/cjs/hoc/SortableItemContext.js +21 -0
- package/cjs/hoc/WithConditionalDnDContext.js +138 -0
- package/cjs/hoc/WithDnDSortableItemContext.js +70 -0
- package/cjs/index.js +26 -37
- package/cjs/parts/CheckboxSelectable.js +59 -70
- package/cjs/parts/ChildrenCountDisplayer.js +28 -45
- package/cjs/parts/DnDHandle.js +46 -0
- package/cjs/parts/DropIndicator.js +75 -0
- package/cjs/parts/ExpandCaret.js +83 -85
- package/cjs/parts/Icon.js +31 -46
- package/cjs/parts/NestingSpace.js +35 -43
- package/cjs/parts/RadioSelectable.js +37 -52
- package/cjs/parts/TreeItem.js +141 -147
- package/cjs/parts/TreeItemText.js +95 -88
- package/cjs/parts/TreeList.js +130 -119
- package/cjs/plugins/dnd/TreeDndPlugin.js +7 -59
- package/cjs/plugins/dnd/index.js +9 -28
- package/cjs/plugins/index.js +21 -34
- package/cjs/plugins/roving/TreeRovingPlugin.js +7 -35
- package/cjs/plugins/roving/index.js +9 -28
- package/cjs/plugins/searchable/SearchableTreePlugin.js +7 -35
- package/cjs/plugins/searchable/index.js +9 -28
- package/cjs/plugins/selectable/SelectablePluginTree.js +7 -35
- package/cjs/plugins/selectable/index.js +9 -28
- package/cjs/plugins/toolbar/TreeToolbarPlugin.js +7 -35
- package/cjs/plugins/toolbar/index.js +9 -28
- package/cjs/plugins/tree/TreeDataPlugin.js +7 -35
- package/cjs/plugins/tree/index.js +9 -28
- package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +7 -35
- package/cjs/plugins/virtualization/index.js +9 -28
- package/cjs/react-desc-prop-types.js +54 -82
- package/cjs/related-components/TreeViewSearchBar.js +40 -42
- package/cjs/sharedTypes.js +2 -27
- package/cjs/utils/array-helpers.js +11 -35
- package/cjs/utils/group-expands-helpers.js +59 -86
- package/cjs/utils/keyboard-helpers.js +90 -85
- package/cjs/utils/object-helpers.js +36 -43
- package/cjs/utils/refs-helpers.js +22 -43
- package/cjs/utils/selectable-helper.js +53 -61
- package/cjs/utils/string-helpers.js +7 -35
- package/cjs/utils/tree-helpers.js +161 -105
- package/cjs/utils/useInstanceRefActions.js +43 -54
- package/cjs/utils/useTree.js +80 -76
- package/esm/TreeView.js +16 -18
- package/esm/TreeViewContext.js +31 -32
- package/esm/config/cssClassesConstants.js +6 -12
- package/esm/config/useTreeview.js +56 -73
- package/esm/hoc/DnDTreeContext.js +14 -0
- package/esm/hoc/SortableItemContext.js +17 -0
- package/esm/hoc/WithConditionalDnDContext.js +128 -0
- package/esm/hoc/WithDnDSortableItemContext.js +61 -0
- package/esm/index.js +9 -8
- package/esm/parts/CheckboxSelectable.js +46 -36
- package/esm/parts/ChildrenCountDisplayer.js +20 -16
- package/esm/parts/DnDHandle.js +38 -0
- package/esm/parts/DropIndicator.js +68 -0
- package/esm/parts/ExpandCaret.js +72 -54
- package/esm/parts/Icon.js +22 -16
- package/esm/parts/NestingSpace.js +27 -14
- package/esm/parts/RadioSelectable.js +28 -20
- package/esm/parts/TreeItem.js +125 -114
- package/esm/parts/TreeItemText.js +85 -58
- package/esm/parts/TreeList.js +119 -91
- package/esm/plugins/dnd/TreeDndPlugin.js +3 -30
- package/esm/plugins/dnd/index.js +1 -3
- package/esm/plugins/index.js +7 -9
- package/esm/plugins/roving/TreeRovingPlugin.js +3 -6
- package/esm/plugins/roving/index.js +1 -3
- package/esm/plugins/searchable/SearchableTreePlugin.js +3 -6
- package/esm/plugins/searchable/index.js +1 -3
- package/esm/plugins/selectable/SelectablePluginTree.js +3 -6
- package/esm/plugins/selectable/index.js +1 -3
- package/esm/plugins/toolbar/TreeToolbarPlugin.js +3 -6
- package/esm/plugins/toolbar/index.js +1 -3
- package/esm/plugins/tree/TreeDataPlugin.js +3 -6
- package/esm/plugins/tree/index.js +1 -3
- package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +3 -6
- package/esm/plugins/virtualization/index.js +1 -3
- package/esm/react-desc-prop-types.js +44 -47
- package/esm/related-components/TreeViewSearchBar.js +32 -13
- package/esm/sharedTypes.js +1 -2
- package/esm/utils/array-helpers.js +6 -6
- package/esm/utils/group-expands-helpers.js +46 -56
- package/esm/utils/keyboard-helpers.js +74 -46
- package/esm/utils/object-helpers.js +31 -14
- package/esm/utils/refs-helpers.js +19 -15
- package/esm/utils/selectable-helper.js +43 -32
- package/esm/utils/string-helpers.js +3 -6
- package/esm/utils/tree-helpers.js +143 -73
- package/esm/utils/useInstanceRefActions.js +35 -21
- package/esm/utils/useTree.js +59 -35
- package/package.json +35 -19
- package/types/hoc/DnDTreeContext.d.ts +14 -0
- package/types/hoc/SortableItemContext.d.ts +19 -0
- package/types/hoc/WithConditionalDnDContext.d.ts +4 -0
- package/types/hoc/WithDnDSortableItemContext.d.ts +4 -0
- package/types/parts/DnDHandle.d.ts +6 -0
- package/types/parts/DropIndicator.d.ts +10 -0
- package/types/parts/TreeItem.d.ts +4 -11
- package/types/parts/TreeList.d.ts +0 -4
- package/types/plugins/dnd/TreeDndPlugin.d.ts +0 -2
- package/types/react-desc-prop-types.d.ts +17 -3
- package/types/sharedTypes.d.ts +1 -8
- package/types/utils/keyboard-helpers.d.ts +2 -1
- package/types/utils/refs-helpers.d.ts +1 -1
- package/types/utils/tree-helpers.d.ts +4 -1
- package/types/utils/useTree.d.ts +1 -0
- package/cjs/TreeView.js.map +0 -7
- package/cjs/TreeViewContext.js.map +0 -7
- package/cjs/config/cssClassesConstants.js.map +0 -7
- package/cjs/config/useTreeview.js.map +0 -7
- package/cjs/index.js.map +0 -7
- package/cjs/parts/CheckboxSelectable.js.map +0 -7
- package/cjs/parts/ChildrenCountDisplayer.js.map +0 -7
- package/cjs/parts/ExpandCaret.js.map +0 -7
- package/cjs/parts/Icon.js.map +0 -7
- package/cjs/parts/NestingSpace.js.map +0 -7
- package/cjs/parts/RadioSelectable.js.map +0 -7
- package/cjs/parts/TreeItem.js.map +0 -7
- package/cjs/parts/TreeItemText.js.map +0 -7
- package/cjs/parts/TreeList.js.map +0 -7
- package/cjs/plugins/dnd/TreeDndPlugin.js.map +0 -7
- package/cjs/plugins/dnd/index.js.map +0 -7
- package/cjs/plugins/index.js.map +0 -7
- package/cjs/plugins/roving/TreeRovingPlugin.js.map +0 -7
- package/cjs/plugins/roving/index.js.map +0 -7
- package/cjs/plugins/searchable/SearchableTreePlugin.js.map +0 -7
- package/cjs/plugins/searchable/index.js.map +0 -7
- package/cjs/plugins/selectable/SelectablePluginTree.js.map +0 -7
- package/cjs/plugins/selectable/index.js.map +0 -7
- package/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
- package/cjs/plugins/toolbar/index.js.map +0 -7
- package/cjs/plugins/tree/TreeDataPlugin.js.map +0 -7
- package/cjs/plugins/tree/index.js.map +0 -7
- package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
- package/cjs/plugins/virtualization/index.js.map +0 -7
- package/cjs/react-desc-prop-types.js.map +0 -7
- package/cjs/related-components/TreeViewSearchBar.js.map +0 -7
- package/cjs/sharedTypes.js.map +0 -7
- package/cjs/utils/array-helpers.js.map +0 -7
- package/cjs/utils/dnd-helpers.js +0 -146
- package/cjs/utils/dnd-helpers.js.map +0 -7
- package/cjs/utils/group-expands-helpers.js.map +0 -7
- package/cjs/utils/keyboard-helpers.js.map +0 -7
- package/cjs/utils/object-helpers.js.map +0 -7
- package/cjs/utils/refs-helpers.js.map +0 -7
- package/cjs/utils/selectable-helper.js.map +0 -7
- package/cjs/utils/string-helpers.js.map +0 -7
- package/cjs/utils/tree-helpers.js.map +0 -7
- package/cjs/utils/useDnDHelpers.js +0 -199
- package/cjs/utils/useDnDHelpers.js.map +0 -7
- package/cjs/utils/useInstanceRefActions.js.map +0 -7
- package/cjs/utils/useTree.js.map +0 -7
- package/esm/TreeView.js.map +0 -7
- package/esm/TreeViewContext.js.map +0 -7
- package/esm/config/cssClassesConstants.js.map +0 -7
- package/esm/config/useTreeview.js.map +0 -7
- package/esm/index.js.map +0 -7
- package/esm/parts/CheckboxSelectable.js.map +0 -7
- package/esm/parts/ChildrenCountDisplayer.js.map +0 -7
- package/esm/parts/ExpandCaret.js.map +0 -7
- package/esm/parts/Icon.js.map +0 -7
- package/esm/parts/NestingSpace.js.map +0 -7
- package/esm/parts/RadioSelectable.js.map +0 -7
- package/esm/parts/TreeItem.js.map +0 -7
- package/esm/parts/TreeItemText.js.map +0 -7
- package/esm/parts/TreeList.js.map +0 -7
- package/esm/plugins/dnd/TreeDndPlugin.js.map +0 -7
- package/esm/plugins/dnd/index.js.map +0 -7
- package/esm/plugins/index.js.map +0 -7
- package/esm/plugins/roving/TreeRovingPlugin.js.map +0 -7
- package/esm/plugins/roving/index.js.map +0 -7
- package/esm/plugins/searchable/SearchableTreePlugin.js.map +0 -7
- package/esm/plugins/searchable/index.js.map +0 -7
- package/esm/plugins/selectable/SelectablePluginTree.js.map +0 -7
- package/esm/plugins/selectable/index.js.map +0 -7
- package/esm/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
- package/esm/plugins/toolbar/index.js.map +0 -7
- package/esm/plugins/tree/TreeDataPlugin.js.map +0 -7
- package/esm/plugins/tree/index.js.map +0 -7
- package/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
- package/esm/plugins/virtualization/index.js.map +0 -7
- package/esm/react-desc-prop-types.js.map +0 -7
- package/esm/related-components/TreeViewSearchBar.js.map +0 -7
- package/esm/sharedTypes.js.map +0 -7
- package/esm/utils/array-helpers.js.map +0 -7
- package/esm/utils/dnd-helpers.js +0 -117
- package/esm/utils/dnd-helpers.js.map +0 -7
- package/esm/utils/group-expands-helpers.js.map +0 -7
- package/esm/utils/keyboard-helpers.js.map +0 -7
- package/esm/utils/object-helpers.js.map +0 -7
- package/esm/utils/refs-helpers.js.map +0 -7
- package/esm/utils/selectable-helper.js.map +0 -7
- package/esm/utils/string-helpers.js.map +0 -7
- package/esm/utils/tree-helpers.js.map +0 -7
- package/esm/utils/useDnDHelpers.js +0 -170
- package/esm/utils/useDnDHelpers.js.map +0 -7
- package/esm/utils/useInstanceRefActions.js.map +0 -7
- package/esm/utils/useTree.js.map +0 -7
- package/types/utils/dnd-helpers.d.ts +0 -39
- package/types/utils/useDnDHelpers.d.ts +0 -26
package/esm/parts/TreeItem.js
CHANGED
|
@@ -1,123 +1,133 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
7
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
8
|
+
import { useContext, useMemo, useCallback } from 'react';
|
|
9
|
+
import { aggregatedClasses } from '@elliemae/ds-classnames';
|
|
10
|
+
import RadioSelectable from './RadioSelectable.js';
|
|
11
|
+
import CheckboxSelectable from './CheckboxSelectable.js';
|
|
12
|
+
import TreeViewContext from '../TreeViewContext.js';
|
|
13
|
+
import { setMultipleRefs } from '../utils/refs-helpers.js';
|
|
14
|
+
import { useOnItemKeyDown } from '../utils/keyboard-helpers.js';
|
|
15
|
+
import { NestingSpace } from './NestingSpace.js';
|
|
16
|
+
import { Icon } from './Icon.js';
|
|
17
|
+
import { ExpandCaret } from './ExpandCaret.js';
|
|
18
|
+
import { TreeItemText } from './TreeItemText.js';
|
|
19
|
+
import { treeItemBlockName, DSTreeViewPrefix } from '../config/cssClassesConstants.js';
|
|
20
|
+
import { DnDHandle } from './DnDHandle.js';
|
|
21
|
+
import { withDnDSortableItemContext } from '../hoc/WithDnDSortableItemContext.js';
|
|
22
|
+
import { SortableItemContext, DropIndicatorPosition } from '../hoc/SortableItemContext.js';
|
|
23
|
+
import DropIndicator from './DropIndicator.js';
|
|
24
|
+
import { jsxs } from 'react/jsx-runtime';
|
|
25
|
+
|
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
+
|
|
28
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
|
+
const TreeListItem = aggregatedClasses('li', {
|
|
30
|
+
'data-testid': treeItemBlockName,
|
|
31
|
+
role: 'treeitem' // temp fix untill we move to styled components
|
|
32
|
+
|
|
19
33
|
})(treeItemBlockName);
|
|
20
|
-
const TreeListItemAddonsWrapper = aggregatedClasses(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
key: `${id}-drag-handle`,
|
|
24
|
-
className: "drag-handle",
|
|
25
|
-
size: "s",
|
|
26
|
-
onMouseDown: (e) => {
|
|
27
|
-
if (e) {
|
|
28
|
-
e.preventDefault();
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
tabIndex: "0"
|
|
32
|
-
}));
|
|
33
|
-
const TreeItem = (props) => {
|
|
34
|
+
const TreeListItemAddonsWrapper = aggregatedClasses('div')(treeItemBlockName, 'addons' // temp fix untill we move to styled components
|
|
35
|
+
);
|
|
36
|
+
const TreeItem = props => {
|
|
34
37
|
const {
|
|
35
38
|
item,
|
|
36
39
|
itemIndex,
|
|
37
40
|
itemWrapperStyle = {},
|
|
38
41
|
virtualItemRef,
|
|
39
42
|
spaceForNestingLevel = 1.5,
|
|
40
|
-
|
|
43
|
+
isDragOverlay = false
|
|
41
44
|
} = props;
|
|
42
|
-
const {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
45
|
+
const {
|
|
46
|
+
id,
|
|
47
|
+
node
|
|
48
|
+
} = item;
|
|
49
|
+
const {
|
|
50
|
+
nodeItemRef
|
|
51
|
+
} = node.model;
|
|
52
|
+
const {
|
|
53
|
+
draggableProps
|
|
54
|
+
} = useContext(SortableItemContext);
|
|
55
|
+
const onItemKeyDown = useOnItemKeyDown(item, draggableProps);
|
|
47
56
|
const ctx = useContext(TreeViewContext);
|
|
48
57
|
const {
|
|
49
|
-
props: {
|
|
50
|
-
|
|
58
|
+
props: {
|
|
59
|
+
disableIcons,
|
|
60
|
+
rightAddons,
|
|
61
|
+
onItemClick,
|
|
62
|
+
onItemFocus,
|
|
63
|
+
rowSize,
|
|
64
|
+
labelOverflow
|
|
65
|
+
},
|
|
51
66
|
withRadioChecks,
|
|
52
67
|
withCheckboxChecks,
|
|
53
68
|
withDragAndDrop,
|
|
54
69
|
selectedItem,
|
|
55
70
|
selectedCheckboxes,
|
|
56
71
|
hoverItem,
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
virtualListHelpers: {
|
|
73
|
+
scrollToIndex
|
|
74
|
+
},
|
|
59
75
|
setHoverItem,
|
|
60
76
|
setSelectedItem,
|
|
61
77
|
setFocusedItem
|
|
62
|
-
} = ctx;
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
} = ctx; // Sortable Items needs to update
|
|
79
|
+
// - the virtual list ref (for react-virtual requirement)
|
|
80
|
+
// - nodeItemRef which is a prop avaiable in the TreeModel nodes
|
|
81
|
+
// - the drag and drop node reference
|
|
82
|
+
|
|
83
|
+
const setItemRefs = ref => {
|
|
84
|
+
setMultipleRefs(virtualItemRef, !isDragOverlay && nodeItemRef, !isDragOverlay && draggableProps && draggableProps.setNodeRef)(ref);
|
|
65
85
|
};
|
|
86
|
+
|
|
87
|
+
const dropIndicatorPosition = draggableProps && draggableProps.shouldShowDropIndicatorPosition && draggableProps.dropIndicatorPosition;
|
|
88
|
+
const isDropIndicatorPositionInside = dropIndicatorPosition === DropIndicatorPosition.Inside;
|
|
89
|
+
const isDragging = draggableProps && draggableProps.isDragging;
|
|
90
|
+
const isDropValid = draggableProps && draggableProps.isDropValid;
|
|
66
91
|
const dropPreviewClassName = useMemo(() => {
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return className;
|
|
78
|
-
}, [withDragAndDrop, relativeMouseCord, isDraggingOverThis]);
|
|
79
|
-
const selectedClassName = useMemo(() => selectedItem?.id === item.id ? "selected" : "", [item.id, selectedItem?.id]);
|
|
80
|
-
const hoverClassName = useMemo(() => hoverItem?.id !== item.id || withDragAndDrop && isDragging ? "" : "hover", [hoverItem?.id, item.id, withDragAndDrop, isDragging]);
|
|
92
|
+
if (isDropIndicatorPositionInside) {
|
|
93
|
+
const className = "".concat(DSTreeViewPrefix, "-").concat(treeItemBlockName).concat(isDropValid ? '--valid' : '--invalid', "-drop-in");
|
|
94
|
+
return className;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return '';
|
|
98
|
+
}, [isDropIndicatorPositionInside, isDropValid]);
|
|
99
|
+
const dragOverlayClassName = useMemo(() => isDragOverlay ? 'drag-overlay' : '', [isDragOverlay]);
|
|
100
|
+
const selectedClassName = useMemo(() => (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id) === item.id && !isDragOverlay ? 'selected' : '', [isDragOverlay, item.id, selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id]);
|
|
101
|
+
const hoverClassName = useMemo(() => !isDragOverlay && ((hoverItem === null || hoverItem === void 0 ? void 0 : hoverItem.id) === item.id || isDragging) ? 'hover' : '', [isDragOverlay, hoverItem === null || hoverItem === void 0 ? void 0 : hoverItem.id, item.id, isDragging]);
|
|
81
102
|
const fixedHeightClassname = useMemo(() => {
|
|
82
|
-
if (labelOverflow ===
|
|
83
|
-
if (rowSize === "compact")
|
|
84
|
-
|
|
85
|
-
return `${DSTreeViewPrefix}-${treeItemBlockName}--fixed-height`;
|
|
103
|
+
if (labelOverflow === 'truncate') {
|
|
104
|
+
if (rowSize === 'compact') return "".concat(DSTreeViewPrefix, "-").concat(treeItemBlockName, "--fixed-height-compact");
|
|
105
|
+
return "".concat(DSTreeViewPrefix, "-").concat(treeItemBlockName, "--fixed-height");
|
|
86
106
|
}
|
|
87
|
-
|
|
107
|
+
|
|
108
|
+
return '';
|
|
88
109
|
}, [labelOverflow, rowSize]);
|
|
89
|
-
const finalClassName = useMemo(() =>
|
|
90
|
-
const handleItemClick = useCallback(
|
|
110
|
+
const finalClassName = useMemo(() => "".concat(dropPreviewClassName, " ").concat(fixedHeightClassname, " ").concat(selectedClassName, " ").concat(hoverClassName, " ").concat(dragOverlayClassName), [dropPreviewClassName, selectedClassName, hoverClassName, fixedHeightClassname, dragOverlayClassName]);
|
|
111
|
+
const handleItemClick = useCallback(e => {
|
|
91
112
|
onItemClick(item, e);
|
|
92
113
|
setFocusedItem(item);
|
|
93
114
|
setSelectedItem(item);
|
|
94
|
-
const itemVirtualIndex = typeof item.virtualIndex ===
|
|
115
|
+
const itemVirtualIndex = typeof item.virtualIndex === 'number' ? item.virtualIndex : -1;
|
|
95
116
|
onItemFocus({
|
|
96
117
|
itemIndex: itemVirtualIndex,
|
|
97
|
-
scrollToItem: (
|
|
118
|
+
scrollToItem: function () {
|
|
119
|
+
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
120
|
+
align: 'start'
|
|
121
|
+
};
|
|
122
|
+
return scrollToIndex(itemVirtualIndex, opts);
|
|
123
|
+
},
|
|
98
124
|
item
|
|
99
125
|
});
|
|
100
126
|
}, [item, scrollToIndex, onItemClick, onItemFocus, setSelectedItem, setFocusedItem]);
|
|
101
|
-
return
|
|
127
|
+
return /*#__PURE__*/jsxs(TreeListItem, {
|
|
102
128
|
tabIndex: 0,
|
|
103
|
-
onMouseMove: (event) => {
|
|
104
|
-
if (withDragAndDrop && onMouseDragOverItem) {
|
|
105
|
-
onMouseDragOverItem({
|
|
106
|
-
event,
|
|
107
|
-
item,
|
|
108
|
-
itemIndex,
|
|
109
|
-
setIsDraggingOverThis,
|
|
110
|
-
openFolderOnHoverTimeout
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
129
|
onMouseLeave: () => {
|
|
115
|
-
if (
|
|
116
|
-
setIsDraggingOverThis(false);
|
|
117
|
-
if (openFolderOnHoverTimeout?.current)
|
|
118
|
-
clearTimeout(openFolderOnHoverTimeout.current);
|
|
119
|
-
}
|
|
120
|
-
if (hoverItem?.id === item.id) {
|
|
130
|
+
if ((hoverItem === null || hoverItem === void 0 ? void 0 : hoverItem.id) === item.id) {
|
|
121
131
|
setHoverItem(null);
|
|
122
132
|
}
|
|
123
133
|
},
|
|
@@ -125,38 +135,39 @@ const TreeItem = (props) => {
|
|
|
125
135
|
setHoverItem(item);
|
|
126
136
|
},
|
|
127
137
|
onClick: handleItemClick,
|
|
138
|
+
onBlur: () => setFocusedItem(null),
|
|
128
139
|
ref: setItemRefs,
|
|
129
|
-
style: {
|
|
140
|
+
style: _objectSpread({}, itemWrapperStyle),
|
|
130
141
|
className: finalClassName,
|
|
131
142
|
"aria-expanded": !!item.isExpanded,
|
|
132
143
|
"aria-selected": !!selectedCheckboxes[item.id],
|
|
133
144
|
"data-id": item.id,
|
|
134
145
|
"data-index": item.virtualIndex,
|
|
135
|
-
onKeyDown: onItemKeyDown
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
TreeListItem,
|
|
160
|
-
TreeListItemAddonsWrapper
|
|
146
|
+
onKeyDown: onItemKeyDown,
|
|
147
|
+
children: [/*#__PURE__*/_jsx(TreeListItemAddonsWrapper, {}, void 0, withDragAndDrop ? /*#__PURE__*/_jsx(DnDHandle, {
|
|
148
|
+
id: id,
|
|
149
|
+
isDragOverlay: isDragOverlay
|
|
150
|
+
}) : null, withRadioChecks && !isDragOverlay ? /*#__PURE__*/_jsx(RadioSelectable, {
|
|
151
|
+
item: item,
|
|
152
|
+
itemIndex: itemIndex
|
|
153
|
+
}) : null, withCheckboxChecks && !isDragOverlay ? /*#__PURE__*/_jsx(CheckboxSelectable, {
|
|
154
|
+
item: item,
|
|
155
|
+
itemIndex: itemIndex
|
|
156
|
+
}) : null, !isDragOverlay && /*#__PURE__*/_jsx(NestingSpace, {
|
|
157
|
+
item: item,
|
|
158
|
+
spaceForNestingLevel: spaceForNestingLevel
|
|
159
|
+
}), !isDragOverlay && /*#__PURE__*/_jsx(ExpandCaret, {
|
|
160
|
+
item: item
|
|
161
|
+
}), !disableIcons ? /*#__PURE__*/_jsx(Icon, {
|
|
162
|
+
item: item
|
|
163
|
+
}) : null), /*#__PURE__*/_jsx(TreeItemText, {
|
|
164
|
+
item: item
|
|
165
|
+
}), rightAddons && /*#__PURE__*/_jsx(TreeListItemAddonsWrapper, {}, void 0, typeof rightAddons === 'function' ? rightAddons(item) : rightAddons), /*#__PURE__*/_jsx(DropIndicator, {
|
|
166
|
+
dropIndicatorPosition: dropIndicatorPosition,
|
|
167
|
+
isDropValid: isDropValid
|
|
168
|
+
})]
|
|
169
|
+
});
|
|
161
170
|
};
|
|
162
|
-
|
|
171
|
+
var TreeItem$1 = withDnDSortableItemContext(TreeItem);
|
|
172
|
+
|
|
173
|
+
export { TreeItem, TreeListItem, TreeListItemAddonsWrapper, TreeItem$1 as default };
|
|
@@ -1,72 +1,99 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import Highlighter from
|
|
4
|
-
import { SimpleTruncatedTooltipText } from
|
|
5
|
-
import { aggregatedClasses } from
|
|
6
|
-
import { ChildrenCountDisplayer } from
|
|
7
|
-
import {
|
|
8
|
-
import TreeViewContext from
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import { useContext, useMemo } from 'react';
|
|
3
|
+
import Highlighter from 'react-highlight-words';
|
|
4
|
+
import { SimpleTruncatedTooltipText } from '@elliemae/ds-truncated-tooltip-text';
|
|
5
|
+
import { aggregatedClasses } from '@elliemae/ds-classnames';
|
|
6
|
+
import { ChildrenCountDisplayer } from './ChildrenCountDisplayer.js';
|
|
7
|
+
import { treeItemBlockName, DSTreeViewPrefix } from '../config/cssClassesConstants.js';
|
|
8
|
+
import TreeViewContext from '../TreeViewContext.js';
|
|
9
|
+
import { jsxs, Fragment } from 'react/jsx-runtime';
|
|
10
|
+
|
|
11
|
+
const ItemContent = aggregatedClasses('div')("".concat(treeItemBlockName, "-content"));
|
|
12
|
+
const ItemValue = aggregatedClasses('span')(treeItemBlockName, 'value'); // const wrapperClassName = `${DSTreeViewPrefix}-${treeItemBlockName}-content`;
|
|
13
|
+
|
|
14
|
+
const classNameModifierWrapAll = "".concat(DSTreeViewPrefix, "-").concat(treeItemBlockName, "__value--wrap-all");
|
|
15
|
+
const classNameModifierTruncate = "".concat(DSTreeViewPrefix, "-").concat(treeItemBlockName, "__value--truncate"); // eslint-disable-next-line react/prop-types
|
|
16
|
+
|
|
17
|
+
const CustomHighlight = _ref => {
|
|
18
|
+
let {
|
|
19
|
+
children
|
|
20
|
+
} = _ref;
|
|
21
|
+
return /*#__PURE__*/_jsx("mark", {
|
|
22
|
+
className: "tree-text-highlight",
|
|
23
|
+
"data-testid": "tree-text-highlight"
|
|
24
|
+
}, void 0, children);
|
|
25
|
+
};
|
|
26
|
+
|
|
17
27
|
function TreeItemText(props) {
|
|
18
|
-
|
|
28
|
+
var _ChildrenCountDisplay, _ChildrenCountDisplay2, _ChildrenCountDisplay3, _ChildrenCountDisplay4;
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
item
|
|
32
|
+
} = props;
|
|
19
33
|
const ctx = useContext(TreeViewContext);
|
|
20
34
|
const {
|
|
21
|
-
props: {
|
|
35
|
+
props: {
|
|
36
|
+
searchQuery,
|
|
37
|
+
showChildrenAmount,
|
|
38
|
+
labelOverflow,
|
|
39
|
+
nameKey
|
|
40
|
+
}
|
|
22
41
|
} = ctx;
|
|
23
42
|
const Text = useMemo(() => {
|
|
24
43
|
const itemLabelText = item[nameKey];
|
|
44
|
+
|
|
25
45
|
if (searchQuery) {
|
|
26
|
-
if (labelOverflow ===
|
|
27
|
-
return
|
|
28
|
-
value:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
if (labelOverflow === 'truncate') {
|
|
47
|
+
return /*#__PURE__*/_jsx(SimpleTruncatedTooltipText, {
|
|
48
|
+
value: /*#__PURE__*/jsxs(Fragment, {
|
|
49
|
+
children: [/*#__PURE__*/_jsx(Highlighter, {
|
|
50
|
+
autoEscape: true,
|
|
51
|
+
highlightTag: CustomHighlight,
|
|
52
|
+
searchWords: [searchQuery],
|
|
53
|
+
textToHighlight: itemLabelText
|
|
54
|
+
}), showChildrenAmount ? _ChildrenCountDisplay || (_ChildrenCountDisplay = /*#__PURE__*/_jsx(ChildrenCountDisplayer, {
|
|
55
|
+
item: item
|
|
56
|
+
})) : null]
|
|
57
|
+
})
|
|
36
58
|
});
|
|
37
59
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
|
|
61
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
62
|
+
children: [/*#__PURE__*/_jsx(Highlighter, {
|
|
63
|
+
autoEscape: true,
|
|
64
|
+
highlightTag: CustomHighlight,
|
|
65
|
+
searchWords: [searchQuery],
|
|
66
|
+
textToHighlight: itemLabelText
|
|
67
|
+
}), showChildrenAmount ? _ChildrenCountDisplay2 || (_ChildrenCountDisplay2 = /*#__PURE__*/_jsx(ChildrenCountDisplayer, {
|
|
68
|
+
item: item
|
|
69
|
+
})) : null]
|
|
70
|
+
});
|
|
46
71
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
72
|
+
|
|
73
|
+
if (labelOverflow === 'truncate') {
|
|
74
|
+
return /*#__PURE__*/_jsx(SimpleTruncatedTooltipText, {
|
|
75
|
+
value: /*#__PURE__*/jsxs(Fragment, {
|
|
76
|
+
children: [itemLabelText, showChildrenAmount ? _ChildrenCountDisplay3 || (_ChildrenCountDisplay3 = /*#__PURE__*/_jsx(ChildrenCountDisplayer, {
|
|
77
|
+
item: item
|
|
78
|
+
})) : null]
|
|
79
|
+
})
|
|
52
80
|
});
|
|
53
81
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
82
|
+
|
|
83
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
84
|
+
children: [itemLabelText, showChildrenAmount ? _ChildrenCountDisplay4 || (_ChildrenCountDisplay4 = /*#__PURE__*/_jsx(ChildrenCountDisplayer, {
|
|
85
|
+
item: item
|
|
86
|
+
})) : null]
|
|
87
|
+
});
|
|
57
88
|
}, [item, searchQuery, nameKey, showChildrenAmount, labelOverflow]);
|
|
58
|
-
let className =
|
|
59
|
-
if (labelOverflow ===
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
className
|
|
67
|
-
}, Text));
|
|
89
|
+
let className = '';
|
|
90
|
+
if (labelOverflow === 'wrap-all') className += "".concat(classNameModifierWrapAll, " ");
|
|
91
|
+
if (labelOverflow === 'truncate') className += "".concat(classNameModifierTruncate, " ");
|
|
92
|
+
return /*#__PURE__*/_jsx(ItemContent, {
|
|
93
|
+
"data-testid": "".concat(treeItemBlockName, "-content")
|
|
94
|
+
}, void 0, /*#__PURE__*/_jsx(ItemValue, {
|
|
95
|
+
className: className
|
|
96
|
+
}, void 0, Text));
|
|
68
97
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
//# sourceMappingURL=TreeItemText.js.map
|
|
98
|
+
|
|
99
|
+
export { TreeItemText };
|