@mezzanine-ui/react 1.0.0-beta.6 → 1.0.0-beta.7
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/Accordion/Accordion.d.ts +23 -1
- package/Accordion/Accordion.js +59 -11
- package/Accordion/AccordionActions.d.ts +13 -0
- package/Accordion/AccordionActions.js +24 -0
- package/Accordion/AccordionContent.d.ts +9 -0
- package/Accordion/{AccordionDetails.js → AccordionContent.js} +4 -6
- package/Accordion/AccordionControlContext.d.ts +2 -2
- package/Accordion/AccordionGroup.d.ts +10 -0
- package/Accordion/AccordionGroup.js +26 -0
- package/Accordion/AccordionTitle.d.ts +14 -0
- package/Accordion/AccordionTitle.js +56 -0
- package/Accordion/index.d.ts +8 -4
- package/Accordion/index.js +4 -2
- package/AutoComplete/AutoComplete.d.ts +20 -6
- package/AutoComplete/AutoComplete.js +118 -30
- package/Backdrop/Backdrop.js +15 -19
- package/Calendar/CalendarDays.js +1 -1
- package/Card/BaseCard.d.ts +11 -0
- package/Card/BaseCard.js +48 -0
- package/Card/BaseCardSkeleton.d.ts +14 -0
- package/Card/BaseCardSkeleton.js +18 -0
- package/Card/CardGroup.d.ts +47 -0
- package/Card/CardGroup.js +147 -0
- package/Card/FourThumbnailCard.d.ts +14 -0
- package/Card/FourThumbnailCard.js +73 -0
- package/Card/FourThumbnailCardSkeleton.d.ts +14 -0
- package/Card/FourThumbnailCardSkeleton.js +20 -0
- package/Card/QuickActionCard.d.ts +12 -0
- package/Card/QuickActionCard.js +23 -0
- package/Card/QuickActionCardSkeleton.d.ts +14 -0
- package/Card/QuickActionCardSkeleton.js +18 -0
- package/Card/SingleThumbnailCard.d.ts +13 -0
- package/Card/SingleThumbnailCard.js +44 -0
- package/Card/SingleThumbnailCardSkeleton.d.ts +19 -0
- package/Card/SingleThumbnailCardSkeleton.js +18 -0
- package/Card/Thumbnail.d.ts +12 -0
- package/Card/Thumbnail.js +18 -0
- package/Card/ThumbnailCardInfo.d.ts +34 -0
- package/Card/ThumbnailCardInfo.js +43 -0
- package/Card/index.d.ts +43 -4
- package/Card/index.js +19 -2
- package/Card/typings.d.ts +442 -0
- package/Checkbox/Checkbox.d.ts +8 -0
- package/Checkbox/Checkbox.js +3 -2
- package/Checkbox/CheckboxGroup.js +1 -1
- package/ContentHeader/ContentHeader.d.ts +22 -70
- package/ContentHeader/ContentHeader.js +1 -1
- package/ContentHeader/ContentHeaderResponsive.d.ts +9 -0
- package/ContentHeader/ContentHeaderResponsive.js +7 -0
- package/ContentHeader/utils.d.ts +3 -3
- package/ContentHeader/utils.js +66 -20
- package/Cropper/Cropper.d.ts +66 -0
- package/Cropper/Cropper.js +115 -0
- package/Cropper/CropperElement.d.ts +10 -0
- package/Cropper/CropperElement.js +892 -0
- package/Cropper/index.d.ts +18 -0
- package/Cropper/index.js +8 -0
- package/Cropper/tools.d.ts +90 -0
- package/Cropper/tools.js +143 -0
- package/Cropper/typings.d.ts +69 -0
- package/Cropper/utils/cropper-calculations.d.ts +39 -0
- package/Cropper/utils/cropper-calculations.js +95 -0
- package/DateTimePicker/DateTimePicker.d.ts +1 -1
- package/DateTimePicker/DateTimePicker.js +14 -1
- package/Dropdown/Dropdown.d.ts +7 -1
- package/Dropdown/Dropdown.js +31 -14
- package/Dropdown/DropdownItem.d.ts +7 -1
- package/Dropdown/DropdownItem.js +36 -6
- package/Dropdown/DropdownItemCard.js +2 -1
- package/FloatingButton/FloatingButton.d.ts +21 -0
- package/FloatingButton/FloatingButton.js +18 -0
- package/FloatingButton/index.d.ts +2 -0
- package/FloatingButton/index.js +1 -0
- package/Form/FormField.d.ts +21 -10
- package/Form/FormField.js +12 -4
- package/Input/Input.js +9 -2
- package/Message/Message.js +1 -1
- package/MultipleDatePicker/MultipleDatePicker.js +2 -2
- package/Navigation/NavigationHeader.js +1 -1
- package/Picker/FormattedInput.d.ts +1 -1
- package/Picker/FormattedInput.js +2 -1
- package/Picker/PickerTriggerWithSeparator.d.ts +10 -0
- package/Picker/PickerTriggerWithSeparator.js +2 -2
- package/Picker/useDateInputFormatter.d.ts +6 -0
- package/Picker/useDateInputFormatter.js +4 -1
- package/Select/Select.d.ts +2 -8
- package/Select/Select.js +12 -33
- package/Select/SelectTrigger.js +21 -7
- package/Select/index.d.ts +0 -4
- package/Select/index.js +0 -2
- package/Select/typings.d.ts +0 -4
- package/Select/useSelectTriggerTags.d.ts +1 -1
- package/Select/useSelectTriggerTags.js +9 -6
- package/Separator/Separator.d.ts +14 -0
- package/Separator/Separator.js +17 -0
- package/Separator/index.d.ts +2 -0
- package/Separator/index.js +1 -0
- package/Table/utils/useTableRowSelection.js +6 -0
- package/Tag/TagGroup.d.ts +4 -2
- package/Tag/TagGroup.js +7 -4
- package/TextField/TextField.d.ts +1 -1
- package/TextField/TextField.js +63 -9
- package/TimePanel/TimePanelColumn.js +19 -12
- package/index.d.ts +27 -28
- package/index.js +23 -25
- package/package.json +4 -4
- package/Accordion/AccordionDetails.d.ts +0 -9
- package/Accordion/AccordionSummary.d.ts +0 -18
- package/Accordion/AccordionSummary.js +0 -51
- package/Alert/Alert.d.ts +0 -20
- package/Alert/Alert.js +0 -18
- package/Alert/index.d.ts +0 -3
- package/Alert/index.js +0 -1
- package/Card/Card.d.ts +0 -51
- package/Card/Card.js +0 -20
- package/Card/CardActions.d.ts +0 -34
- package/Card/CardActions.js +0 -15
- package/ConfirmActions/ConfirmActions.d.ts +0 -46
- package/ConfirmActions/ConfirmActions.js +0 -15
- package/ConfirmActions/index.d.ts +0 -2
- package/ConfirmActions/index.js +0 -1
- package/Select/Option.d.ts +0 -18
- package/Select/Option.js +0 -45
- package/Select/TreeSelect.d.ts +0 -72
- package/Select/TreeSelect.js +0 -205
- package/Tree/Tree.d.ts +0 -70
- package/Tree/Tree.js +0 -139
- package/Tree/TreeNode.d.ts +0 -40
- package/Tree/TreeNode.js +0 -50
- package/Tree/TreeNodeList.d.ts +0 -24
- package/Tree/TreeNodeList.js +0 -28
- package/Tree/getTreeNodeEntities.d.ts +0 -11
- package/Tree/getTreeNodeEntities.js +0 -92
- package/Tree/index.d.ts +0 -13
- package/Tree/index.js +0 -7
- package/Tree/toggleValue.d.ts +0 -4
- package/Tree/toggleValue.js +0 -19
- package/Tree/traverseTree.d.ts +0 -2
- package/Tree/traverseTree.js +0 -11
- package/Tree/typings.d.ts +0 -16
- package/Tree/useTreeExpandedValue.d.ts +0 -14
- package/Tree/useTreeExpandedValue.js +0 -33
package/Select/TreeSelect.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { selectClasses } from '@mezzanine-ui/core/select';
|
|
4
|
-
import { forwardRef, useContext, useMemo, useRef, useState } from 'react';
|
|
5
|
-
import { useClickAway } from '../hooks/useClickAway.js';
|
|
6
|
-
import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
7
|
-
import { useIsomorphicLayoutEffect } from '../hooks/useIsomorphicLayoutEffect.js';
|
|
8
|
-
import SelectTrigger from './SelectTrigger.js';
|
|
9
|
-
import { FormControlContext } from '../Form/FormControlContext.js';
|
|
10
|
-
import { traverseTree } from '../Tree/traverseTree.js';
|
|
11
|
-
import InputTriggerPopper from '../_internal/InputTriggerPopper/InputTriggerPopper.js';
|
|
12
|
-
import Menu from '../Menu/Menu.js';
|
|
13
|
-
import Tree from '../Tree/Tree.js';
|
|
14
|
-
import { toggleValue } from '../Tree/toggleValue.js';
|
|
15
|
-
import cx from 'clsx';
|
|
16
|
-
|
|
17
|
-
const TreeSelect = forwardRef((props, ref) => {
|
|
18
|
-
var _a;
|
|
19
|
-
const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
|
|
20
|
-
const { className, clearable = false, defaultExpandAll, depth, disabled = disabledFromFormControl || false, disabledValues, error = severity === 'error' || false, expandControllerRef, fullWidth = fullWidthFromFormControl || false, inputProps, inputRef, itemsInView = 4, menuMaxHeight, menuProps, menuRole = 'listbox', menuSize, mode = 'single', onBlur, onChange: onChangeProp, onExpand: onExpandProp, onFocus, options, placeholder = '', popperOptions, prefix, renderValue, required = requiredFromFormControl || false, sameWidth = false, size, suffixActionIcon, treeProps, value: valueProp, } = props;
|
|
21
|
-
const { className: treeClassName, ...restTreeProps } = treeProps || {};
|
|
22
|
-
const { width, border, ...restStyle } = (menuProps === null || menuProps === void 0 ? void 0 : menuProps.style) || {};
|
|
23
|
-
const multiple = mode === 'multiple';
|
|
24
|
-
/** Compute panel width */
|
|
25
|
-
const panelWidth = useMemo(() => {
|
|
26
|
-
if (width) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const base = multiple ? 224 : 208;
|
|
30
|
-
const indent = 16;
|
|
31
|
-
function getWidth(resultDepth) {
|
|
32
|
-
return (resultDepth - 1) * indent + base;
|
|
33
|
-
}
|
|
34
|
-
if (depth) {
|
|
35
|
-
return getWidth(depth);
|
|
36
|
-
}
|
|
37
|
-
function maxDepth(object, counter = 1) {
|
|
38
|
-
if (object.siblings) {
|
|
39
|
-
return Math.max(...object.siblings.map((sibling) => maxDepth(sibling, counter + 1)));
|
|
40
|
-
}
|
|
41
|
-
return counter;
|
|
42
|
-
}
|
|
43
|
-
const computedMaxDepth = options.reduce((acc, current) => {
|
|
44
|
-
const currentDepth = maxDepth(current);
|
|
45
|
-
return currentDepth > acc ? currentDepth : acc;
|
|
46
|
-
}, 0);
|
|
47
|
-
return getWidth(computedMaxDepth);
|
|
48
|
-
}, [depth, multiple, options, width]);
|
|
49
|
-
/** Popper positioning */
|
|
50
|
-
const nodeRef = useRef(null);
|
|
51
|
-
const controlRef = useRef(null);
|
|
52
|
-
const popperRef = useRef(null);
|
|
53
|
-
const composedRef = useComposeRefs([ref, controlRef]);
|
|
54
|
-
/** Make popper positioning dynamically by computing styles every time value prop changes */
|
|
55
|
-
const controllerRef = useRef(null);
|
|
56
|
-
useIsomorphicLayoutEffect(() => {
|
|
57
|
-
var _a, _b;
|
|
58
|
-
(_b = (_a = controllerRef.current) === null || _a === void 0 ? void 0 : _a.update) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
59
|
-
}, [valueProp]);
|
|
60
|
-
/** Open control */
|
|
61
|
-
const [open, toggleOpen] = useState(false);
|
|
62
|
-
const onOpen = () => {
|
|
63
|
-
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
64
|
-
toggleOpen(true);
|
|
65
|
-
};
|
|
66
|
-
const onClose = () => {
|
|
67
|
-
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
68
|
-
toggleOpen(false);
|
|
69
|
-
};
|
|
70
|
-
const onToggleOpen = () => {
|
|
71
|
-
if (open) {
|
|
72
|
-
onClose();
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
onOpen();
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const onTextFieldClick = disabled
|
|
79
|
-
? undefined
|
|
80
|
-
: () => {
|
|
81
|
-
onToggleOpen();
|
|
82
|
-
};
|
|
83
|
-
const onTextFieldKeydown = disabled
|
|
84
|
-
? undefined
|
|
85
|
-
: (event) => {
|
|
86
|
-
switch (event.code) {
|
|
87
|
-
case 'Enter':
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
89
|
-
onTextFieldClick();
|
|
90
|
-
break;
|
|
91
|
-
case 'ArrowUp':
|
|
92
|
-
case 'ArrowRight':
|
|
93
|
-
case 'ArrowLeft':
|
|
94
|
-
case 'ArrowDown': {
|
|
95
|
-
if (!open) {
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
97
|
-
onTextFieldClick();
|
|
98
|
-
}
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
case 'Tab': {
|
|
102
|
-
if (open) {
|
|
103
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
104
|
-
onTextFieldClick();
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
useClickAway(() => {
|
|
111
|
-
if (!open)
|
|
112
|
-
return;
|
|
113
|
-
return (event) => {
|
|
114
|
-
var _a;
|
|
115
|
-
if (!((_a = popperRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target))) {
|
|
116
|
-
onClose();
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}, controlRef, [open, toggleOpen]);
|
|
120
|
-
/** Trigger input props */
|
|
121
|
-
const resolvedInputProps = {
|
|
122
|
-
...inputProps,
|
|
123
|
-
'aria-expanded': open,
|
|
124
|
-
placeholder,
|
|
125
|
-
role: 'combobox',
|
|
126
|
-
};
|
|
127
|
-
/** Tags close handler */
|
|
128
|
-
const onTagClose = onChangeProp && valueProp
|
|
129
|
-
? (target) => {
|
|
130
|
-
onChangeProp(valueProp.filter((v) => v.id !== target.id));
|
|
131
|
-
}
|
|
132
|
-
: undefined;
|
|
133
|
-
/** Clear method */
|
|
134
|
-
const onClear = clearable && onChangeProp
|
|
135
|
-
? () => {
|
|
136
|
-
onChangeProp([]);
|
|
137
|
-
}
|
|
138
|
-
: undefined;
|
|
139
|
-
/** Map options to tree nodes */
|
|
140
|
-
function mapOptionToNode(option) {
|
|
141
|
-
var _a;
|
|
142
|
-
return {
|
|
143
|
-
label: option.name,
|
|
144
|
-
value: option.id,
|
|
145
|
-
dynamicNodesFetching: option.dynamicChildrenFetching,
|
|
146
|
-
nodes: (_a = option.siblings) === null || _a === void 0 ? void 0 : _a.map((sibling) => mapOptionToNode(sibling)),
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
function flattenOptions(targets) {
|
|
150
|
-
const optionsMap = {};
|
|
151
|
-
function mapOptionsToSelectValue(optionsToMap) {
|
|
152
|
-
optionsToMap.forEach((optionToMap) => {
|
|
153
|
-
optionsMap[optionToMap.id] = {
|
|
154
|
-
id: optionToMap.id,
|
|
155
|
-
name: optionToMap.name,
|
|
156
|
-
};
|
|
157
|
-
if (optionToMap.siblings) {
|
|
158
|
-
mapOptionsToSelectValue(optionToMap.siblings);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
mapOptionsToSelectValue(targets);
|
|
163
|
-
return optionsMap;
|
|
164
|
-
}
|
|
165
|
-
const optionMap = flattenOptions(options);
|
|
166
|
-
const nodes = options.map((option) => mapOptionToNode(option));
|
|
167
|
-
/** Map selected values */
|
|
168
|
-
const selectedValues = valueProp === null || valueProp === void 0 ? void 0 : valueProp.map((v) => mapOptionToNode(v).value);
|
|
169
|
-
const onSelect = onChangeProp
|
|
170
|
-
? (values) => {
|
|
171
|
-
const selectValues = values.map((currentValue) => optionMap[currentValue]);
|
|
172
|
-
onChangeProp(selectValues);
|
|
173
|
-
}
|
|
174
|
-
: undefined;
|
|
175
|
-
/** Controlled expanded value to avoid expanded values cleanup after panel toggled */
|
|
176
|
-
const [expandedValues, setExpandedValues] = useState(() => {
|
|
177
|
-
const currentExpandedValues = [];
|
|
178
|
-
if (defaultExpandAll) {
|
|
179
|
-
traverseTree(nodes, (node) => {
|
|
180
|
-
if (node.nodes) {
|
|
181
|
-
currentExpandedValues.push(node.value);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
return currentExpandedValues;
|
|
186
|
-
});
|
|
187
|
-
const onExpand = (value) => {
|
|
188
|
-
const newExpandedValues = toggleValue(value, expandedValues);
|
|
189
|
-
setExpandedValues(newExpandedValues);
|
|
190
|
-
onExpandProp === null || onExpandProp === void 0 ? void 0 : onExpandProp(value);
|
|
191
|
-
};
|
|
192
|
-
// Convert valueProp to single value for single mode
|
|
193
|
-
const triggerValue = multiple ? valueProp : ((_a = valueProp === null || valueProp === void 0 ? void 0 : valueProp[0]) !== null && _a !== void 0 ? _a : undefined);
|
|
194
|
-
// Adapt renderValue for single mode
|
|
195
|
-
const adaptedRenderValue = renderValue && !multiple
|
|
196
|
-
? (value) => renderValue(value !== null && value !== void 0 ? value : null)
|
|
197
|
-
: undefined;
|
|
198
|
-
return (jsxs("div", { ref: nodeRef, className: selectClasses.treeSelect, children: [jsx(SelectTrigger, { ref: composedRef, active: open, className: className, clearable: clearable, disabled: disabled, error: error, fullWidth: fullWidth, inputProps: resolvedInputProps, inputRef: inputRef, mode: mode, onClear: onClear, onClick: onTextFieldClick, onKeyDown: onTextFieldKeydown, onTagClose: onTagClose, prefix: prefix, readOnly: true, ...(mode === 'single' && adaptedRenderValue ? { renderValue: adaptedRenderValue } : {}), required: required, size: size, suffixActionIcon: suffixActionIcon, value: triggerValue }), jsx(InputTriggerPopper, { ref: popperRef, anchor: controlRef, className: selectClasses.popper, controllerRef: controllerRef, open: open, options: popperOptions, sameWidth: sameWidth, children: jsx(Menu, { itemsInView: itemsInView, maxHeight: menuMaxHeight, role: menuRole, size: menuSize, style: {
|
|
199
|
-
...restStyle,
|
|
200
|
-
border: border || 0,
|
|
201
|
-
width: width || `${panelWidth}px`,
|
|
202
|
-
}, children: jsx(Tree, { ...restTreeProps, ref: ref, className: cx(selectClasses.tree, treeClassName), disabledValues: disabledValues, expandControllerRef: expandControllerRef, expandedValues: expandedValues, multiple: multiple, nodes: nodes, onExpand: onExpand, onSelect: onSelect, selectMethod: "target", selectable: true, values: selectedValues }) }) })] }));
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
export { TreeSelect as default };
|
package/Tree/Tree.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { TreeNodeValue, TreeSelectMethod } from '@mezzanine-ui/core/tree';
|
|
2
|
-
import { Ref } from 'react';
|
|
3
|
-
import { GetTreeNodeEntitiesProps } from './getTreeNodeEntities';
|
|
4
|
-
import { TreeNodeListElementProps, TreeNodeListProps } from './TreeNodeList';
|
|
5
|
-
import { TreeExpandControl, TreeNodeProp } from './typings';
|
|
6
|
-
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
7
|
-
export interface TreeProps extends Pick<TreeNodeListProps, 'multiple' | 'selectable' | 'size' | 'treeNodeProps' | 'treeNodeRefs' | 'onExpand'>, Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'children' | 'defaultChecked' | 'defaultValue' | 'onChange' | 'onSelect'> {
|
|
8
|
-
/**
|
|
9
|
-
* Controls whether to expand all at first render.
|
|
10
|
-
*/
|
|
11
|
-
defaultExpandAll?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Provide if certain nodes should be disabled.
|
|
14
|
-
* Notice that there are two conditions for auto disabling.
|
|
15
|
-
* First, if the siblings are all disabled, the parent will be disabled as well.
|
|
16
|
-
* Second, if the parent is disabled, all its siblings will be disabled as well.
|
|
17
|
-
*/
|
|
18
|
-
disabledValues?: GetTreeNodeEntitiesProps['disabledValues'];
|
|
19
|
-
/**
|
|
20
|
-
* Provide if access to expand control is needed.
|
|
21
|
-
*/
|
|
22
|
-
expandControllerRef?: Ref<TreeExpandControl | null>;
|
|
23
|
-
/**
|
|
24
|
-
* By default expanded values of `Tree` is uncontrolled.
|
|
25
|
-
* However, you may specify `expandedValues` to gain full control.
|
|
26
|
-
* If that's the case, you should provide `onExpand` as well.
|
|
27
|
-
* Notices that if `expandedValues` is provided, `expandControllerRef` will not get the control methods.
|
|
28
|
-
*/
|
|
29
|
-
expandedValues?: TreeNodeValue[];
|
|
30
|
-
/**
|
|
31
|
-
* By default Tree only passes the leaf values to the select handler.
|
|
32
|
-
* If you want to include all the node values, set `includeNodeValue` to `true`.
|
|
33
|
-
*/
|
|
34
|
-
includeNodeValue?: GetTreeNodeEntitiesProps['includeNodeValue'];
|
|
35
|
-
/**
|
|
36
|
-
* The nodes to be rendered in `Tree`
|
|
37
|
-
*/
|
|
38
|
-
nodes: TreeNodeProp[];
|
|
39
|
-
/**
|
|
40
|
-
* By default expanded values of `Tree` is uncontrolled, where `onExpand` is not needed.
|
|
41
|
-
* However, you may specify `expandedValues` to gain full control
|
|
42
|
-
* and that's where you should provide `onExpand` together.
|
|
43
|
-
*/
|
|
44
|
-
onExpand?: TreeNodeListProps['onExpand'];
|
|
45
|
-
/**
|
|
46
|
-
* Select handler for `Tree`. Receives all the current selected values as its argument.
|
|
47
|
-
*/
|
|
48
|
-
onSelect?: (selectedValues: TreeNodeValue[]) => void;
|
|
49
|
-
/**
|
|
50
|
-
* Controls the singular select logic.
|
|
51
|
-
* `Toggle` means the value will be toggled.
|
|
52
|
-
* `Target` means the target value will always be the result value and will not deselect if click again.
|
|
53
|
-
* @default 'toggle''
|
|
54
|
-
*/
|
|
55
|
-
selectMethod?: TreeSelectMethod;
|
|
56
|
-
/**
|
|
57
|
-
* Other `ul` props you may provide to `TreeNodeList` component.
|
|
58
|
-
* A common use-case is to override classes and styles.
|
|
59
|
-
*/
|
|
60
|
-
treeNodeListProps?: TreeNodeListElementProps;
|
|
61
|
-
/**
|
|
62
|
-
* The selected values are controlled values. Should be use with `selectable`.
|
|
63
|
-
*/
|
|
64
|
-
values?: TreeNodeValue | TreeNodeValue[];
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* The react component for `mezzanine` tree.
|
|
68
|
-
*/
|
|
69
|
-
declare const Tree: import("react").ForwardRefExoticComponent<TreeProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
70
|
-
export default Tree;
|
package/Tree/Tree.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { treeClasses } from '@mezzanine-ui/core/tree';
|
|
3
|
-
import { forwardRef, useMemo, useImperativeHandle } from 'react';
|
|
4
|
-
import castArray from 'lodash/castArray';
|
|
5
|
-
import without from 'lodash/without';
|
|
6
|
-
import uniq from 'lodash/uniq';
|
|
7
|
-
import { getTreeNodeEntities } from './getTreeNodeEntities.js';
|
|
8
|
-
import { toggleValueWithStatusControl } from './toggleValue.js';
|
|
9
|
-
import { traverseTree } from './traverseTree.js';
|
|
10
|
-
import TreeNodeList from './TreeNodeList.js';
|
|
11
|
-
import { useTreeExpandedValue } from './useTreeExpandedValue.js';
|
|
12
|
-
import cx from 'clsx';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The react component for `mezzanine` tree.
|
|
16
|
-
*/
|
|
17
|
-
const Tree = forwardRef(function Tree(props, ref) {
|
|
18
|
-
const { className, defaultExpandAll, disabledValues, expandControllerRef, expandedValues: expandedValuesProp, includeNodeValue, multiple, nodes, onExpand: onExpandProp, onSelect: onSelectProp, selectMethod = 'toggle', selectable, size, treeNodeListProps, treeNodeProps, treeNodeRefs, values, ...restRootProp } = props;
|
|
19
|
-
const selectedValues = values
|
|
20
|
-
? castArray(values)
|
|
21
|
-
: undefined;
|
|
22
|
-
const { expandedValues, onExpand, setExpandedValues } = useTreeExpandedValue({
|
|
23
|
-
nodes,
|
|
24
|
-
defaultExpandAll,
|
|
25
|
-
expandedValues: expandedValuesProp,
|
|
26
|
-
onExpand: onExpandProp,
|
|
27
|
-
});
|
|
28
|
-
const treeEntities = useMemo(() => getTreeNodeEntities({
|
|
29
|
-
disabledValues,
|
|
30
|
-
expandedValues,
|
|
31
|
-
includeNodeValue,
|
|
32
|
-
multiple,
|
|
33
|
-
nodes,
|
|
34
|
-
selectedValues,
|
|
35
|
-
}), [
|
|
36
|
-
disabledValues,
|
|
37
|
-
expandedValues,
|
|
38
|
-
includeNodeValue,
|
|
39
|
-
multiple,
|
|
40
|
-
nodes,
|
|
41
|
-
selectedValues,
|
|
42
|
-
]);
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
44
|
-
const displayNodes = nodes.map((node) => treeEntities.get(node.value).node);
|
|
45
|
-
const getAllExpandSiblingValues = (value) => {
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
47
|
-
const currentEntity = treeEntities.get(value);
|
|
48
|
-
const allSiblingEntities = currentEntity.siblings;
|
|
49
|
-
const allSiblingNodes = allSiblingEntities === null || allSiblingEntities === void 0 ? void 0 : allSiblingEntities.map(({ node }) => node);
|
|
50
|
-
const allNodeValues = [];
|
|
51
|
-
if (allSiblingNodes === null || allSiblingNodes === void 0 ? void 0 : allSiblingNodes.length) {
|
|
52
|
-
allNodeValues.push(currentEntity.node.value);
|
|
53
|
-
traverseTree(allSiblingNodes, (node) => {
|
|
54
|
-
var _a;
|
|
55
|
-
if ((_a = node.nodes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
56
|
-
allNodeValues.push(node.value);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return allNodeValues;
|
|
61
|
-
};
|
|
62
|
-
const collapse = (value) => {
|
|
63
|
-
setExpandedValues(expandedValues.filter((v) => v !== value));
|
|
64
|
-
};
|
|
65
|
-
const collapseAll = () => {
|
|
66
|
-
const allNodeValues = nodes.reduce((acc, currentNode) => [
|
|
67
|
-
...acc,
|
|
68
|
-
...getAllExpandSiblingValues(currentNode.value),
|
|
69
|
-
], []);
|
|
70
|
-
const uniqAllNodeValues = uniq(allNodeValues);
|
|
71
|
-
const newExpandedValues = without(expandedValues, ...uniqAllNodeValues);
|
|
72
|
-
setExpandedValues(newExpandedValues);
|
|
73
|
-
};
|
|
74
|
-
const collapseAllFrom = (value) => {
|
|
75
|
-
const allNodeValues = getAllExpandSiblingValues(value);
|
|
76
|
-
const newExpandedValues = without(expandedValues, ...allNodeValues);
|
|
77
|
-
setExpandedValues(newExpandedValues);
|
|
78
|
-
};
|
|
79
|
-
const expand = (value) => {
|
|
80
|
-
setExpandedValues(uniq([...expandedValues, value]));
|
|
81
|
-
};
|
|
82
|
-
const expandAll = () => {
|
|
83
|
-
const allNodeValues = nodes.reduce((acc, currentNode) => [
|
|
84
|
-
...acc,
|
|
85
|
-
...getAllExpandSiblingValues(currentNode.value),
|
|
86
|
-
], []);
|
|
87
|
-
const newExpandedValues = uniq([...expandedValues, ...allNodeValues]);
|
|
88
|
-
setExpandedValues(newExpandedValues);
|
|
89
|
-
};
|
|
90
|
-
const expandAllFrom = (value) => {
|
|
91
|
-
const allNodeValues = getAllExpandSiblingValues(value);
|
|
92
|
-
const newExpandedValues = uniq([...expandedValues, ...allNodeValues]);
|
|
93
|
-
setExpandedValues(newExpandedValues);
|
|
94
|
-
};
|
|
95
|
-
useImperativeHandle(expandControllerRef, () => {
|
|
96
|
-
if (expandedValuesProp) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
collapse,
|
|
101
|
-
collapseAll,
|
|
102
|
-
collapseAllFrom,
|
|
103
|
-
expand,
|
|
104
|
-
expandAll,
|
|
105
|
-
expandAllFrom,
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
const onMultipleSelect = onSelectProp
|
|
109
|
-
? (value) => {
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
111
|
-
const targetEntity = treeEntities.get(value);
|
|
112
|
-
const { selected } = targetEntity.node;
|
|
113
|
-
const newCheckedValues = toggleValueWithStatusControl(!!selected, targetEntity.values, selectedValues || []);
|
|
114
|
-
onSelectProp(newCheckedValues);
|
|
115
|
-
}
|
|
116
|
-
: undefined;
|
|
117
|
-
const onSingleSelect = onSelectProp
|
|
118
|
-
? (value) => {
|
|
119
|
-
var _a;
|
|
120
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
121
|
-
const targetEntity = treeEntities.get(value);
|
|
122
|
-
const { selected } = targetEntity.node;
|
|
123
|
-
if (!((_a = targetEntity.siblings) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
124
|
-
if (selectMethod === 'target') {
|
|
125
|
-
onSelectProp([value]);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
const newCheckedValues = toggleValueWithStatusControl(!!selected, targetEntity.values, []);
|
|
129
|
-
onSelectProp(newCheckedValues);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
: undefined;
|
|
134
|
-
const selectHandler = multiple ? onMultipleSelect : onSingleSelect;
|
|
135
|
-
const onSelect = selectable ? selectHandler : undefined;
|
|
136
|
-
return (jsx("div", { ref: ref, className: cx(treeClasses.host, className), ...restRootProp, children: jsx(TreeNodeList, { ...treeNodeListProps, multiple: multiple, nodes: displayNodes, onExpand: onExpand, onSelect: onSelect, selectable: selectable, size: size, treeNodeProps: treeNodeProps, treeNodeRefs: treeNodeRefs }) }));
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
export { Tree as default };
|
package/Tree/TreeNode.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { TreeNodeValue, TreeSize } from '@mezzanine-ui/core/tree';
|
|
2
|
-
import { CollapseProps } from '../Transition';
|
|
3
|
-
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
4
|
-
import { TreeNodeData } from './typings';
|
|
5
|
-
export type TreeNodeElementProps = Omit<NativeElementPropsWithoutKeyAndRef<'li'>, 'children' | 'value' | 'onSelect'>;
|
|
6
|
-
export interface TreeNodeProps extends TreeNodeData, TreeNodeElementProps {
|
|
7
|
-
/**
|
|
8
|
-
* Provided children will be wrapped under `Collapse`.
|
|
9
|
-
*/
|
|
10
|
-
children?: CollapseProps['children'];
|
|
11
|
-
/**
|
|
12
|
-
* The list item will be rendered as `Checkbox` if multiple set to true.
|
|
13
|
-
* @default false
|
|
14
|
-
*/
|
|
15
|
-
multiple?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Handler for caret icon click event. Receive current node value as its argument.
|
|
18
|
-
*/
|
|
19
|
-
onExpand?: (value: TreeNodeValue) => void;
|
|
20
|
-
/**
|
|
21
|
-
* Handler for label element click event. Receive current node value as its argument.
|
|
22
|
-
* Must use with selectable setting to `true`.
|
|
23
|
-
*/
|
|
24
|
-
onSelect?: (value: TreeNodeValue) => void;
|
|
25
|
-
/**
|
|
26
|
-
* Controls whether to be selectable.
|
|
27
|
-
* @default false
|
|
28
|
-
*/
|
|
29
|
-
selectable?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Sizes for the layout.
|
|
32
|
-
* @default 'medium'
|
|
33
|
-
*/
|
|
34
|
-
size?: TreeSize;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* The react component for `mezzanine` tree node.
|
|
38
|
-
*/
|
|
39
|
-
declare const TreeNode: import("react").ForwardRefExoticComponent<TreeNodeProps & import("react").RefAttributes<HTMLLIElement>>;
|
|
40
|
-
export default TreeNode;
|
package/Tree/TreeNode.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { treeClasses } from '@mezzanine-ui/core/tree';
|
|
4
|
-
import { CaretRightIcon } from '@mezzanine-ui/icons';
|
|
5
|
-
import { forwardRef, useContext, useMemo } from 'react';
|
|
6
|
-
import { MezzanineConfig } from '../Provider/context.js';
|
|
7
|
-
import Spin from '../Spin/Spin.js';
|
|
8
|
-
import Typography from '../Typography/Typography.js';
|
|
9
|
-
import Icon from '../Icon/Icon.js';
|
|
10
|
-
import Checkbox from '../Checkbox/Checkbox.js';
|
|
11
|
-
import Collapse from '../Transition/Collapse.js';
|
|
12
|
-
import cx from 'clsx';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The react component for `mezzanine` tree node.
|
|
16
|
-
*/
|
|
17
|
-
const TreeNode = forwardRef(function TreeNode(props, ref) {
|
|
18
|
-
const { size: globalSize } = useContext(MezzanineConfig);
|
|
19
|
-
const { children, className, disabled, dynamicNodesFetching, expanded, indeterminate, label, multiple = false, onExpand: onExpandProp, onSelect: onSelectProp, selectable = false, selected, size = globalSize, value, ...restRootProps } = props;
|
|
20
|
-
const variant = useMemo(() => {
|
|
21
|
-
if (size === 'small') {
|
|
22
|
-
return 'input';
|
|
23
|
-
}
|
|
24
|
-
if (size === 'large') {
|
|
25
|
-
return 'input';
|
|
26
|
-
}
|
|
27
|
-
return 'input';
|
|
28
|
-
}, [size]);
|
|
29
|
-
const onExpand = onExpandProp
|
|
30
|
-
? () => {
|
|
31
|
-
onExpandProp(value);
|
|
32
|
-
}
|
|
33
|
-
: undefined;
|
|
34
|
-
const onSelect = selectable && onSelectProp && !disabled
|
|
35
|
-
? () => {
|
|
36
|
-
onSelectProp(value);
|
|
37
|
-
}
|
|
38
|
-
: undefined;
|
|
39
|
-
const mayHaveChildren = children || dynamicNodesFetching;
|
|
40
|
-
return (jsxs("li", { ref: ref, ...restRootProps, className: cx(treeClasses.node, treeClasses.nodeSize(size), className), children: [jsxs("div", { className: treeClasses.nodeStem, children: [mayHaveChildren ? (jsx(Icon, { icon: CaretRightIcon, className: cx(treeClasses.nodeCaret, {
|
|
41
|
-
[treeClasses.nodeCaretExpanded]: expanded,
|
|
42
|
-
}), role: "button", onClick: onExpand })) : (jsx("div", {})), multiple ? (jsx(Checkbox, { checked: !!selected, disabled: disabled, indeterminate: indeterminate, onChange: onSelect, value: `${value}`, children: label })) : (jsx(Typography, { component: "span", variant: variant, onClick: onSelect, className: cx(treeClasses.nodeLabel, {
|
|
43
|
-
[treeClasses.nodeLabelSelectable]: !children && selectable,
|
|
44
|
-
[treeClasses.nodeLabelIndeterminate]: indeterminate,
|
|
45
|
-
[treeClasses.nodeLabelActive]: selected,
|
|
46
|
-
[treeClasses.nodeLabelDisabled]: disabled,
|
|
47
|
-
}), children: label }))] }), mayHaveChildren && (jsx(Collapse, { in: expanded, appear: false, children: children || jsx(Spin, { loading: true, iconProps: { size: 16 } }) }))] }));
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
export { TreeNode as default };
|
package/Tree/TreeNodeList.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
2
|
-
import { TreeNodeElementProps, TreeNodeProps } from './TreeNode';
|
|
3
|
-
import { TreeNodeData, TreeNodeRefs } from './typings';
|
|
4
|
-
export type TreeNodeListElementProps = Omit<NativeElementPropsWithoutKeyAndRef<'ul'>, 'children' | 'onSelect'>;
|
|
5
|
-
export interface TreeNodeListProps extends TreeNodeListElementProps, Pick<TreeNodeProps, 'multiple' | 'onExpand' | 'onSelect' | 'selectable' | 'size'> {
|
|
6
|
-
/**
|
|
7
|
-
* Given nodes will be passed to `TreeNode` component orderly.
|
|
8
|
-
*/
|
|
9
|
-
nodes?: TreeNodeData['nodes'];
|
|
10
|
-
/**
|
|
11
|
-
* Other props you may provide to `TreeNode` component. A common use-case is to override classes and styles.
|
|
12
|
-
*/
|
|
13
|
-
treeNodeProps?: TreeNodeElementProps;
|
|
14
|
-
/**
|
|
15
|
-
* Provide if you want to access every list element. Paired with node key and the element.
|
|
16
|
-
* Usage example: `const treeNodeRefs = useRef<TreeNodeRefsShape | undefined>(undefined)`
|
|
17
|
-
*/
|
|
18
|
-
treeNodeRefs?: TreeNodeRefs;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* The react component for `mezzanine` tree node list.
|
|
22
|
-
*/
|
|
23
|
-
declare const TreeNodeList: import("react").ForwardRefExoticComponent<TreeNodeListProps & import("react").RefAttributes<HTMLUListElement>>;
|
|
24
|
-
export default TreeNodeList;
|
package/Tree/TreeNodeList.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { treeClasses } from '@mezzanine-ui/core/tree';
|
|
3
|
-
import { forwardRef } from 'react';
|
|
4
|
-
import TreeNode from './TreeNode.js';
|
|
5
|
-
import cx from 'clsx';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The react component for `mezzanine` tree node list.
|
|
9
|
-
*/
|
|
10
|
-
const TreeNodeList = forwardRef((props, ref) => {
|
|
11
|
-
const { className, multiple, nodes, onExpand, onSelect, selectable, size = 'medium', treeNodeProps, treeNodeRefs, ...restRootProp } = props;
|
|
12
|
-
const getNodeRefHandler = treeNodeRefs
|
|
13
|
-
? (value) => (node) => {
|
|
14
|
-
treeNodeRefs.current = {
|
|
15
|
-
...treeNodeRefs.current,
|
|
16
|
-
[value]: node,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
: undefined;
|
|
20
|
-
if (!(nodes === null || nodes === void 0 ? void 0 : nodes.length))
|
|
21
|
-
return null;
|
|
22
|
-
return (jsx("ul", { ...restRootProp, ref: ref, className: cx(treeClasses.nodeList, treeClasses.nodeListSize(size), className), children: nodes.map((node) => {
|
|
23
|
-
const { value, nodes: siblingNodes, ...restNodeProps } = node;
|
|
24
|
-
return (jsx(TreeNode, { ref: getNodeRefHandler === null || getNodeRefHandler === void 0 ? void 0 : getNodeRefHandler(value), ...treeNodeProps, multiple: multiple, onExpand: onExpand, onSelect: onSelect, selectable: selectable, size: size, value: value, ...restNodeProps, children: (siblingNodes === null || siblingNodes === void 0 ? void 0 : siblingNodes.length) ? (jsx(TreeNodeList, { ...restRootProp, className: className, multiple: multiple, nodes: siblingNodes, onExpand: onExpand, onSelect: onSelect, selectable: selectable, size: size, treeNodeRefs: treeNodeRefs })) : undefined }, value));
|
|
25
|
-
}) }));
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
export { TreeNodeList as default };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TreeNodeValue } from '@mezzanine-ui/core/tree';
|
|
2
|
-
import { TreeNodeData, TreeNodeEntities } from './typings';
|
|
3
|
-
export interface GetTreeNodeEntitiesProps {
|
|
4
|
-
disabledValues?: TreeNodeValue[];
|
|
5
|
-
expandedValues?: TreeNodeValue[];
|
|
6
|
-
includeNodeValue?: boolean;
|
|
7
|
-
multiple?: boolean;
|
|
8
|
-
nodes: TreeNodeData[];
|
|
9
|
-
selectedValues?: TreeNodeValue[];
|
|
10
|
-
}
|
|
11
|
-
export declare function getTreeNodeEntities({ disabledValues, expandedValues, includeNodeValue, multiple, nodes, selectedValues, }: GetTreeNodeEntitiesProps): TreeNodeEntities;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import xor from 'lodash/xor';
|
|
2
|
-
|
|
3
|
-
function getTreeNodeEntities({ disabledValues, expandedValues, includeNodeValue = false, multiple, nodes, selectedValues, }) {
|
|
4
|
-
const entities = new Map();
|
|
5
|
-
const selectedValueMap = (selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.length)
|
|
6
|
-
? new Map(selectedValues.map((val) => [val, true]))
|
|
7
|
-
: undefined;
|
|
8
|
-
const expandedValueMap = (expandedValues === null || expandedValues === void 0 ? void 0 : expandedValues.length)
|
|
9
|
-
? new Map(expandedValues.map((val) => [val, true]))
|
|
10
|
-
: undefined;
|
|
11
|
-
const disabledValueMap = (disabledValues === null || disabledValues === void 0 ? void 0 : disabledValues.length)
|
|
12
|
-
? new Map(disabledValues.map((val) => [val, true]))
|
|
13
|
-
: undefined;
|
|
14
|
-
function getTreeEntity(node, parentDisabled) {
|
|
15
|
-
const { nodes: currentSiblings, value } = node;
|
|
16
|
-
const selected = selectedValueMap === null || selectedValueMap === void 0 ? void 0 : selectedValueMap.get(value);
|
|
17
|
-
const expanded = expandedValueMap === null || expandedValueMap === void 0 ? void 0 : expandedValueMap.get(value);
|
|
18
|
-
const disabled = disabledValueMap === null || disabledValueMap === void 0 ? void 0 : disabledValueMap.get(value);
|
|
19
|
-
const entity = {
|
|
20
|
-
node: {
|
|
21
|
-
...node,
|
|
22
|
-
disabled: parentDisabled || disabled,
|
|
23
|
-
expanded,
|
|
24
|
-
selected,
|
|
25
|
-
},
|
|
26
|
-
values: [],
|
|
27
|
-
};
|
|
28
|
-
if (!(currentSiblings === null || currentSiblings === void 0 ? void 0 : currentSiblings.length)) {
|
|
29
|
-
entities.set(entity.node.value, entity);
|
|
30
|
-
entity.values.push(value);
|
|
31
|
-
return entity;
|
|
32
|
-
}
|
|
33
|
-
const { anyIndeterminate, directSiblings, disabledValues: siblingDisabledValues, selectedValues: siblingSelectedValues, siblingNodes, siblings: siblingEntities, values: siblingValues, } = currentSiblings.reduce((acc, sibling) => {
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
35
|
-
const siblingEntity = getTreeEntity(sibling, parentDisabled || disabled);
|
|
36
|
-
const currentAnyIndeterminate = siblingEntity.node.indeterminate || acc.anyIndeterminate;
|
|
37
|
-
return {
|
|
38
|
-
anyIndeterminate: currentAnyIndeterminate,
|
|
39
|
-
directSiblings: [...acc.directSiblings, siblingEntity.node.value],
|
|
40
|
-
disabledValues: siblingEntity.node.disabled
|
|
41
|
-
? [...acc.disabledValues, siblingEntity.node.value]
|
|
42
|
-
: acc.disabledValues,
|
|
43
|
-
selectedValues: siblingEntity.node.selected
|
|
44
|
-
? [...acc.selectedValues, siblingEntity.node.value]
|
|
45
|
-
: acc.selectedValues,
|
|
46
|
-
siblingNodes: [...acc.siblingNodes, siblingEntity.node],
|
|
47
|
-
siblings: [...acc.siblings, siblingEntity],
|
|
48
|
-
values: [...acc.values, ...siblingEntity.values],
|
|
49
|
-
};
|
|
50
|
-
}, {
|
|
51
|
-
anyIndeterminate: false,
|
|
52
|
-
directSiblings: [],
|
|
53
|
-
disabledValues: [],
|
|
54
|
-
selectedValues: [],
|
|
55
|
-
siblingNodes: [],
|
|
56
|
-
siblings: [],
|
|
57
|
-
values: [],
|
|
58
|
-
});
|
|
59
|
-
entity.node.nodes = siblingNodes;
|
|
60
|
-
entity.siblings = siblingEntities;
|
|
61
|
-
entity.values.push(...siblingValues);
|
|
62
|
-
if (includeNodeValue) {
|
|
63
|
-
entity.values.push(value);
|
|
64
|
-
}
|
|
65
|
-
const shouldDisabled = siblingDisabledValues.length &&
|
|
66
|
-
!xor(siblingDisabledValues, directSiblings).length;
|
|
67
|
-
if (!disabled && shouldDisabled) {
|
|
68
|
-
entity.node.disabled = true;
|
|
69
|
-
}
|
|
70
|
-
if ((anyIndeterminate && !disabled && !shouldDisabled) ||
|
|
71
|
-
(!multiple && siblingSelectedValues.length)) {
|
|
72
|
-
entity.node.selected = false;
|
|
73
|
-
entity.node.indeterminate = true;
|
|
74
|
-
entities.set(entity.node.value, entity);
|
|
75
|
-
return entity;
|
|
76
|
-
}
|
|
77
|
-
const allDirectSiblingChecked = !!(siblingSelectedValues.length &&
|
|
78
|
-
!xor(siblingSelectedValues, directSiblings).length);
|
|
79
|
-
entity.node.selected = allDirectSiblingChecked;
|
|
80
|
-
entity.node.indeterminate = allDirectSiblingChecked
|
|
81
|
-
? false
|
|
82
|
-
: !!siblingSelectedValues.length;
|
|
83
|
-
entities.set(entity.node.value, entity);
|
|
84
|
-
return entity;
|
|
85
|
-
}
|
|
86
|
-
nodes.forEach((node) => {
|
|
87
|
-
getTreeEntity(node, disabledValueMap === null || disabledValueMap === void 0 ? void 0 : disabledValueMap.get(node.value));
|
|
88
|
-
});
|
|
89
|
-
return entities;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { getTreeNodeEntities };
|