Socket
Socket
Sign inDemoInstall

rc-tree-select

Package Overview
Dependencies
Maintainers
6
Versions
259
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rc-tree-select - npm Package Compare versions

Comparing version 4.3.3 to 4.4.0-alpha.0

es/generate.d.ts

5

es/Context.d.ts
import * as React from 'react';
import type { IconType } from 'rc-tree/lib/interface';
import type { Key, LegacyDataNode } from './interface';
import type { FlattenDataNode, Key, LegacyDataNode, RawValueType } from './interface';
import type { SkipType } from './hooks/useKeyValueMapping';
interface ContextProps {

@@ -21,4 +22,6 @@ checkable: boolean | React.ReactNode;

onTreeLoad: (loadedKeys: Key[]) => void;
getEntityByKey: (key: Key, skipType?: SkipType, ignoreDisabledCheck?: boolean) => FlattenDataNode;
getEntityByValue: (value: RawValueType, skipType?: SkipType, ignoreDisabledCheck?: boolean) => FlattenDataNode;
}
export declare const SelectContext: React.Context<ContextProps>;
export {};

3

es/hooks/useTreeData.js
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
var _excluded = ["key", "value", "children"];
import * as React from 'react';

@@ -54,3 +55,3 @@ import warning from "rc-util/es/warning";

children = node.children,
rest = _objectWithoutProperties(node, ["key", "value", "children"]);
rest = _objectWithoutProperties(node, _excluded);

@@ -57,0 +58,0 @@ var mergedValue = 'value' in node ? value : key;

@@ -9,4 +9,2 @@ import _extends from "@babel/runtime/helpers/esm/extends";

import { SelectContext } from './Context';
import useKeyValueMapping from './hooks/useKeyValueMapping';
import useKeyValueMap from './hooks/useKeyValueMap';
var HIDDEN_STYLE = {

@@ -54,3 +52,5 @@ width: 0,

treeMotion = _React$useContext.treeMotion,
onTreeLoad = _React$useContext.onTreeLoad;
onTreeLoad = _React$useContext.onTreeLoad,
getEntityByKey = _React$useContext.getEntityByKey,
getEntityByValue = _React$useContext.getEntityByValue;

@@ -62,15 +62,4 @@ var treeRef = React.useRef();

return next[0] && prev[1] !== next[1];
});
}); // ========================== Values ==========================
var _useKeyValueMap = useKeyValueMap(flattenOptions),
_useKeyValueMap2 = _slicedToArray(_useKeyValueMap, 2),
cacheKeyMap = _useKeyValueMap2[0],
cacheValueMap = _useKeyValueMap2[1];
var _useKeyValueMapping = useKeyValueMapping(cacheKeyMap, cacheValueMap),
_useKeyValueMapping2 = _slicedToArray(_useKeyValueMapping, 2),
getEntityByKey = _useKeyValueMapping2[0],
getEntityByValue = _useKeyValueMapping2[1]; // ========================== Values ==========================
var valueKeys = React.useMemo(function () {

@@ -77,0 +66,0 @@ return checkedKeys.map(function (val) {

@@ -1,61 +0,67 @@

import * as React from 'react';
import type { SelectProps, RefSelectProps } from 'rc-select/lib/generate';
import type { IconType } from 'rc-tree/lib/interface';
import type { FilterFunc } from 'rc-select/lib/interface/generator';
import type { Key, DefaultValueType, DataNode, LabelValueType, SimpleModeConfig, ChangeEventExtra, LegacyDataNode } from './interface';
import type { CheckedStrategy } from './utils/strategyUtil';
import { SHOW_ALL, SHOW_PARENT, SHOW_CHILD } from './utils/strategyUtil';
export interface TreeSelectProps<ValueType = DefaultValueType> extends Omit<SelectProps<DataNode[], ValueType>, 'onChange' | 'mode' | 'menuItemSelectedIcon' | 'dropdownAlign' | 'backfill' | 'getInputElement' | 'optionLabelProp' | 'tokenSeparators' | 'filterOption'> {
multiple?: boolean;
showArrow?: boolean;
showSearch?: boolean;
open?: boolean;
defaultOpen?: boolean;
value?: ValueType;
defaultValue?: ValueType;
disabled?: boolean;
placeholder?: React.ReactNode;
/** @deprecated Use `searchValue` instead */
inputValue?: string;
searchValue?: string;
autoClearSearchValue?: boolean;
maxTagPlaceholder?: (omittedValues: LabelValueType[]) => React.ReactNode;
loadData?: (dataNode: LegacyDataNode) => Promise<unknown>;
treeNodeFilterProp?: string;
treeNodeLabelProp?: string;
treeDataSimpleMode?: boolean | SimpleModeConfig;
treeExpandedKeys?: Key[];
treeDefaultExpandedKeys?: Key[];
treeLoadedKeys?: Key[];
treeCheckable?: boolean | React.ReactNode;
treeCheckStrictly?: boolean;
showCheckedStrategy?: CheckedStrategy;
treeDefaultExpandAll?: boolean;
treeData?: DataNode[];
treeLine?: boolean;
treeIcon?: IconType;
showTreeIcon?: boolean;
switcherIcon?: IconType;
treeMotion?: any;
children?: React.ReactNode;
filterTreeNode?: boolean | FilterFunc<LegacyDataNode>;
dropdownPopupAlign?: any;
onSearch?: (value: string) => void;
onChange?: (value: ValueType, labelList: React.ReactNode[], extra: ChangeEventExtra) => void;
onTreeExpand?: (expandedKeys: Key[]) => void;
onTreeLoad?: (loadedKeys: Key[]) => void;
onDropdownVisibleChange?: (open: boolean) => void;
/** `searchPlaceholder` has been removed since search box has been merged into input box */
searchPlaceholder?: React.ReactNode;
}
declare class TreeSelect<ValueType = DefaultValueType> extends React.Component<TreeSelectProps<ValueType>, {}> {
static TreeNode: React.FC<import("./TreeNode").TreeNodeProps>;
static SHOW_ALL: typeof SHOW_ALL;
static SHOW_PARENT: typeof SHOW_PARENT;
static SHOW_CHILD: typeof SHOW_CHILD;
selectRef: React.RefObject<RefSelectProps>;
focus: () => void;
blur: () => void;
render(): JSX.Element;
}
/// <reference types="react" />
import { TreeSelectProps } from './generate';
declare const TreeSelect: {
new <ValueType = import("./interface").DefaultValueType>(props: TreeSelectProps<ValueType> | Readonly<TreeSelectProps<ValueType>>): {
selectRef: import("react").RefObject<import("rc-select/lib/generate").RefSelectProps>;
focus: () => void;
blur: () => void;
render(): JSX.Element;
context: any;
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<TreeSelectProps<ValueType>>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: () => void): void;
forceUpdate(callback?: () => void): void;
readonly props: Readonly<TreeSelectProps<ValueType>> & Readonly<{
children?: import("react").ReactNode;
}>;
state: Readonly<{}>;
refs: {
[key: string]: import("react").ReactInstance;
};
componentDidMount?(): void;
shouldComponentUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): boolean;
componentWillUnmount?(): void;
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
getSnapshotBeforeUpdate?(prevProps: Readonly<TreeSelectProps<ValueType>>, prevState: Readonly<{}>): any;
componentDidUpdate?(prevProps: Readonly<TreeSelectProps<ValueType>>, prevState: Readonly<{}>, snapshot?: any): void;
componentWillMount?(): void;
UNSAFE_componentWillMount?(): void;
componentWillReceiveProps?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextContext: any): void;
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextContext: any): void;
componentWillUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): void;
UNSAFE_componentWillUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): void;
};
new <ValueType = import("./interface").DefaultValueType>(props: TreeSelectProps<ValueType>, context: any): {
selectRef: import("react").RefObject<import("rc-select/lib/generate").RefSelectProps>;
focus: () => void;
blur: () => void;
render(): JSX.Element;
context: any;
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<TreeSelectProps<ValueType>>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: () => void): void;
forceUpdate(callback?: () => void): void;
readonly props: Readonly<TreeSelectProps<ValueType>> & Readonly<{
children?: import("react").ReactNode;
}>;
state: Readonly<{}>;
refs: {
[key: string]: import("react").ReactInstance;
};
componentDidMount?(): void;
shouldComponentUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): boolean;
componentWillUnmount?(): void;
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
getSnapshotBeforeUpdate?(prevProps: Readonly<TreeSelectProps<ValueType>>, prevState: Readonly<{}>): any;
componentDidUpdate?(prevProps: Readonly<TreeSelectProps<ValueType>>, prevState: Readonly<{}>, snapshot?: any): void;
componentWillMount?(): void;
UNSAFE_componentWillMount?(): void;
componentWillReceiveProps?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextContext: any): void;
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextContext: any): void;
componentWillUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): void;
UNSAFE_componentWillUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): void;
};
TreeNode: import("react").FC<import("./TreeNode").TreeNodeProps>;
SHOW_ALL: "SHOW_ALL";
SHOW_PARENT: "SHOW_PARENT";
SHOW_CHILD: "SHOW_CHILD";
contextType?: import("react").Context<any>;
};
export { TreeSelectProps };
export default TreeSelect;

@@ -1,484 +0,7 @@

import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _extends from "@babel/runtime/helpers/esm/extends";
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _typeof from "@babel/runtime/helpers/esm/typeof";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import * as React from 'react';
import { useMemo } from 'react';
import generateSelector from "rc-select/es/generate";
import { getLabeledValue } from "rc-select/es/utils/valueUtil";
import { convertDataToEntities } from "rc-tree/es/utils/treeUtil";
import { conductCheck } from "rc-tree/es/utils/conductUtil";
import { INTERNAL_PROPS_MARK } from "rc-select/es/interface/generator";
import useMergedState from "rc-util/es/hooks/useMergedState";
import warning from "rc-util/es/warning";
import generate from './generate';
import OptionList from './OptionList';
import TreeNode from './TreeNode';
import { flattenOptions, filterOptions, isValueDisabled, findValueOption, addValue, removeValue, getRawValueLabeled, toArray } from './utils/valueUtil';
import warningProps from './utils/warningPropsUtil';
import { SelectContext } from './Context';
import useTreeData from './hooks/useTreeData';
import useKeyValueMap from './hooks/useKeyValueMap';
import useKeyValueMapping from './hooks/useKeyValueMapping';
import { formatStrategyKeys, SHOW_ALL, SHOW_PARENT, SHOW_CHILD } from './utils/strategyUtil';
import { fillAdditionalInfo } from './utils/legacyUtil';
import useSelectValues from './hooks/useSelectValues';
var OMIT_PROPS = ['expandedKeys', 'treeData', 'treeCheckable', 'showCheckedStrategy', 'searchPlaceholder', 'treeLine', 'treeIcon', 'showTreeIcon', 'switcherIcon', 'treeNodeFilterProp', 'filterTreeNode', 'dropdownPopupAlign', 'treeDefaultExpandAll', 'treeCheckStrictly', 'treeExpandedKeys', 'treeLoadedKeys', 'treeMotion', 'onTreeExpand', 'onTreeLoad', 'loadData', 'treeDataSimpleMode', 'treeNodeLabelProp', 'treeDefaultExpandedKeys'];
var RefSelect = generateSelector({
var TreeSelect = generate({
prefixCls: 'rc-tree-select',
components: {
optionList: OptionList
},
// Not use generate since we will handle ourself
convertChildrenToData: function convertChildrenToData() {
return null;
},
flattenOptions: flattenOptions,
// Handle `optionLabelProp` in TreeSelect component
getLabeledValue: getLabeledValue,
filterOptions: filterOptions,
isValueDisabled: isValueDisabled,
findValueOption: findValueOption,
omitDOMProps: function omitDOMProps(props) {
var cloneProps = _objectSpread({}, props);
OMIT_PROPS.forEach(function (prop) {
delete cloneProps[prop];
});
return cloneProps;
}
optionList: OptionList
});
RefSelect.displayName = 'Select';
var RefTreeSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
var multiple = props.multiple,
treeCheckable = props.treeCheckable,
treeCheckStrictly = props.treeCheckStrictly,
_props$showCheckedStr = props.showCheckedStrategy,
showCheckedStrategy = _props$showCheckedStr === void 0 ? 'SHOW_CHILD' : _props$showCheckedStr,
labelInValue = props.labelInValue,
loadData = props.loadData,
treeLoadedKeys = props.treeLoadedKeys,
_props$treeNodeFilter = props.treeNodeFilterProp,
treeNodeFilterProp = _props$treeNodeFilter === void 0 ? 'value' : _props$treeNodeFilter,
treeNodeLabelProp = props.treeNodeLabelProp,
treeDataSimpleMode = props.treeDataSimpleMode,
treeData = props.treeData,
treeExpandedKeys = props.treeExpandedKeys,
treeDefaultExpandedKeys = props.treeDefaultExpandedKeys,
treeDefaultExpandAll = props.treeDefaultExpandAll,
children = props.children,
treeIcon = props.treeIcon,
showTreeIcon = props.showTreeIcon,
switcherIcon = props.switcherIcon,
treeLine = props.treeLine,
treeMotion = props.treeMotion,
filterTreeNode = props.filterTreeNode,
dropdownPopupAlign = props.dropdownPopupAlign,
onChange = props.onChange,
onTreeExpand = props.onTreeExpand,
onTreeLoad = props.onTreeLoad,
onDropdownVisibleChange = props.onDropdownVisibleChange,
onSelect = props.onSelect,
onDeselect = props.onDeselect;
var mergedCheckable = treeCheckable || treeCheckStrictly;
var mergedMultiple = multiple || mergedCheckable;
var treeConduction = treeCheckable && !treeCheckStrictly;
var mergedLabelInValue = treeCheckStrictly || labelInValue; // ========================== Ref ==========================
var selectRef = React.useRef(null);
React.useImperativeHandle(ref, function () {
return {
scrollTo: selectRef.current.scrollTo,
focus: selectRef.current.focus,
blur: selectRef.current.blur
};
}); // ======================= Tree Data =======================
// Legacy both support `label` or `title` if not set.
// We have to fallback to function to handle this
var getTreeNodeTitle = function getTreeNodeTitle(node) {
if (!treeData) {
return node.title;
}
return node.label || node.title;
};
var getTreeNodeLabelProp = function getTreeNodeLabelProp(node) {
if (treeNodeLabelProp) {
return node[treeNodeLabelProp];
}
return getTreeNodeTitle(node);
};
var mergedTreeData = useTreeData(treeData, children, {
getLabelProp: getTreeNodeTitle,
simpleMode: treeDataSimpleMode
});
var flattedOptions = useMemo(function () {
return flattenOptions(mergedTreeData);
}, [mergedTreeData]);
var _useKeyValueMap = useKeyValueMap(flattedOptions),
_useKeyValueMap2 = _slicedToArray(_useKeyValueMap, 2),
cacheKeyMap = _useKeyValueMap2[0],
cacheValueMap = _useKeyValueMap2[1];
var _useKeyValueMapping = useKeyValueMapping(cacheKeyMap, cacheValueMap),
_useKeyValueMapping2 = _slicedToArray(_useKeyValueMapping, 2),
getEntityByKey = _useKeyValueMapping2[0],
getEntityByValue = _useKeyValueMapping2[1]; // Only generate keyEntities for check conduction when is `treeCheckable`
var _useMemo = useMemo(function () {
if (treeConduction) {
return convertDataToEntities(mergedTreeData);
}
return {
keyEntities: null
};
}, [mergedTreeData, treeCheckable, treeCheckStrictly]),
conductKeyEntities = _useMemo.keyEntities; // ========================= Value =========================
var _useMergedState = useMergedState(props.defaultValue, {
value: props.value
}),
_useMergedState2 = _slicedToArray(_useMergedState, 2),
value = _useMergedState2[0],
setValue = _useMergedState2[1];
/** Get `missingRawValues` which not exist in the tree yet */
var splitRawValues = function splitRawValues(newRawValues) {
var missingRawValues = [];
var existRawValues = []; // Keep missing value in the cache
newRawValues.forEach(function (val) {
if (getEntityByValue(val)) {
existRawValues.push(val);
} else {
missingRawValues.push(val);
}
});
return {
missingRawValues: missingRawValues,
existRawValues: existRawValues
};
};
var _useMemo2 = useMemo(function () {
var valueHalfCheckedKeys = [];
var newRawValues = [];
toArray(value).forEach(function (item) {
if (item && _typeof(item) === 'object' && 'value' in item) {
if (item.halfChecked && treeCheckStrictly) {
var entity = getEntityByValue(item.value);
valueHalfCheckedKeys.push(entity ? entity.key : item.value);
} else {
newRawValues.push(item.value);
}
} else {
newRawValues.push(item);
}
}); // We need do conduction of values
if (treeConduction) {
var _splitRawValues = splitRawValues(newRawValues),
missingRawValues = _splitRawValues.missingRawValues,
existRawValues = _splitRawValues.existRawValues;
var keyList = existRawValues.map(function (val) {
return getEntityByValue(val).key;
});
var _conductCheck = conductCheck(keyList, true, conductKeyEntities),
checkedKeys = _conductCheck.checkedKeys,
halfCheckedKeys = _conductCheck.halfCheckedKeys;
return [[].concat(_toConsumableArray(missingRawValues), _toConsumableArray(checkedKeys.map(function (key) {
return getEntityByKey(key).data.value;
}))), halfCheckedKeys];
}
return [newRawValues, valueHalfCheckedKeys];
}, [value, mergedMultiple, mergedLabelInValue, treeCheckable, treeCheckStrictly]),
_useMemo3 = _slicedToArray(_useMemo2, 2),
rawValues = _useMemo3[0],
rawHalfCheckedKeys = _useMemo3[1];
var selectValues = useSelectValues(rawValues, {
treeConduction: treeConduction,
value: value,
showCheckedStrategy: showCheckedStrategy,
conductKeyEntities: conductKeyEntities,
getEntityByValue: getEntityByValue,
getEntityByKey: getEntityByKey,
getLabelProp: getTreeNodeLabelProp
});
var triggerChange = function triggerChange(newRawValues, extra, source) {
setValue(mergedMultiple ? newRawValues : newRawValues[0]);
if (onChange) {
var eventValues = newRawValues;
if (treeConduction && showCheckedStrategy !== 'SHOW_ALL') {
var keyList = newRawValues.map(function (val) {
var entity = getEntityByValue(val);
return entity ? entity.key : val;
});
var formattedKeyList = formatStrategyKeys(keyList, showCheckedStrategy, conductKeyEntities);
eventValues = formattedKeyList.map(function (key) {
var entity = getEntityByKey(key);
return entity ? entity.data.value : key;
});
}
var _ref = extra || {
triggerValue: undefined,
selected: undefined
},
triggerValue = _ref.triggerValue,
selected = _ref.selected;
var returnValues = mergedLabelInValue ? getRawValueLabeled(eventValues, value, getEntityByValue, getTreeNodeLabelProp) : eventValues; // We need fill half check back
if (treeCheckStrictly) {
var halfValues = rawHalfCheckedKeys.map(function (key) {
var entity = getEntityByKey(key);
return entity ? entity.data.value : key;
}).filter(function (val) {
return !eventValues.includes(val);
});
returnValues = [].concat(_toConsumableArray(returnValues), _toConsumableArray(getRawValueLabeled(halfValues, value, getEntityByValue, getTreeNodeLabelProp)));
}
var additionalInfo = {
// [Legacy] Always return as array contains label & value
preValue: selectValues,
triggerValue: triggerValue
}; // [Legacy] Fill legacy data if user query.
// This is expansive that we only fill when user query
// https://github.com/react-component/tree-select/blob/fe33eb7c27830c9ac70cd1fdb1ebbe7bc679c16a/src/Select.jsx
var showPosition = true;
if (treeCheckStrictly || source === 'selection' && !selected) {
showPosition = false;
}
fillAdditionalInfo(additionalInfo, triggerValue, newRawValues, mergedTreeData, showPosition);
if (mergedCheckable) {
additionalInfo.checked = selected;
} else {
additionalInfo.selected = selected;
}
onChange(mergedMultiple ? returnValues : returnValues[0], mergedLabelInValue ? null : eventValues.map(function (val) {
var entity = getEntityByValue(val);
return entity ? getTreeNodeLabelProp(entity.data) : null;
}), additionalInfo);
}
};
var onInternalSelect = function onInternalSelect(selectValue, option, source) {
var eventValue = mergedLabelInValue ? selectValue : selectValue;
if (!mergedMultiple) {
// Single mode always set value
triggerChange([selectValue], {
selected: true,
triggerValue: selectValue
}, source);
} else {
var newRawValues = addValue(rawValues, selectValue); // Add keys if tree conduction
if (treeConduction) {
// Should keep missing values
var _splitRawValues2 = splitRawValues(newRawValues),
missingRawValues = _splitRawValues2.missingRawValues,
existRawValues = _splitRawValues2.existRawValues;
var keyList = existRawValues.map(function (val) {
return getEntityByValue(val).key;
});
var _conductCheck2 = conductCheck(keyList, true, conductKeyEntities),
checkedKeys = _conductCheck2.checkedKeys;
newRawValues = [].concat(_toConsumableArray(missingRawValues), _toConsumableArray(checkedKeys.map(function (key) {
return getEntityByKey(key).data.value;
})));
}
triggerChange(newRawValues, {
selected: true,
triggerValue: selectValue
}, source);
}
if (onSelect) {
onSelect(eventValue, option);
}
};
var onInternalDeselect = function onInternalDeselect(selectValue, option, source) {
var eventValue = mergedLabelInValue ? selectValue : selectValue;
var newRawValues = removeValue(rawValues, selectValue); // Remove keys if tree conduction
if (treeConduction) {
var _splitRawValues3 = splitRawValues(newRawValues),
missingRawValues = _splitRawValues3.missingRawValues,
existRawValues = _splitRawValues3.existRawValues;
var keyList = existRawValues.map(function (val) {
return getEntityByValue(val).key;
});
var _conductCheck3 = conductCheck(keyList, {
checked: false,
halfCheckedKeys: rawHalfCheckedKeys
}, conductKeyEntities),
checkedKeys = _conductCheck3.checkedKeys;
newRawValues = [].concat(_toConsumableArray(missingRawValues), _toConsumableArray(checkedKeys.map(function (key) {
return getEntityByKey(key).data.value;
})));
}
triggerChange(newRawValues, {
selected: false,
triggerValue: selectValue
}, source);
if (onDeselect) {
onDeselect(eventValue, option);
}
};
var onInternalClear = function onInternalClear() {
triggerChange([], null, 'clear');
}; // ========================= Open ==========================
var onInternalDropdownVisibleChange = React.useCallback(function (open) {
if (onDropdownVisibleChange) {
var legacyParam = {};
Object.defineProperty(legacyParam, 'documentClickClose', {
get: function get() {
warning(false, 'Second param of `onDropdownVisibleChange` has been removed.');
return false;
}
});
onDropdownVisibleChange(open, legacyParam);
}
}, [onDropdownVisibleChange]); // ======================== Warning ========================
if (process.env.NODE_ENV !== 'production') {
warningProps(props);
} // ======================== Render =========================
// We pass some props into select props style
var selectProps = {
optionLabelProp: null,
optionFilterProp: treeNodeFilterProp,
dropdownAlign: dropdownPopupAlign,
internalProps: {
mark: INTERNAL_PROPS_MARK,
onClear: onInternalClear,
skipTriggerChange: true,
skipTriggerSelect: true,
onRawSelect: onInternalSelect,
onRawDeselect: onInternalDeselect
}
};
if ('filterTreeNode' in props) {
selectProps.filterOption = filterTreeNode;
}
return /*#__PURE__*/React.createElement(SelectContext.Provider, {
value: {
checkable: mergedCheckable,
loadData: loadData,
treeLoadedKeys: treeLoadedKeys,
onTreeLoad: onTreeLoad,
checkedKeys: rawValues,
halfCheckedKeys: rawHalfCheckedKeys,
treeDefaultExpandAll: treeDefaultExpandAll,
treeExpandedKeys: treeExpandedKeys,
treeDefaultExpandedKeys: treeDefaultExpandedKeys,
onTreeExpand: onTreeExpand,
treeIcon: treeIcon,
treeMotion: treeMotion,
showTreeIcon: showTreeIcon,
switcherIcon: switcherIcon,
treeLine: treeLine,
treeNodeFilterProp: treeNodeFilterProp
}
}, /*#__PURE__*/React.createElement(RefSelect, _extends({
ref: selectRef,
mode: mergedMultiple ? 'multiple' : null
}, props, selectProps, {
value: selectValues // We will handle this ourself since we need calculate conduction
,
labelInValue: true,
options: mergedTreeData,
onChange: null,
onSelect: null,
onDeselect: null,
onDropdownVisibleChange: onInternalDropdownVisibleChange
})));
}); // Use class component since typescript not support generic
// by `forwardRef` with function component yet.
var TreeSelect = /*#__PURE__*/function (_React$Component) {
_inherits(TreeSelect, _React$Component);
var _super = _createSuper(TreeSelect);
function TreeSelect() {
var _this;
_classCallCheck(this, TreeSelect);
_this = _super.apply(this, arguments);
_this.selectRef = /*#__PURE__*/React.createRef();
_this.focus = function () {
_this.selectRef.current.focus();
};
_this.blur = function () {
_this.selectRef.current.blur();
};
return _this;
}
_createClass(TreeSelect, [{
key: "render",
value: function render() {
return /*#__PURE__*/React.createElement(RefTreeSelect, _extends({
ref: this.selectRef
}, this.props));
}
}]);
return TreeSelect;
}(React.Component);
TreeSelect.TreeNode = TreeNode;
TreeSelect.SHOW_ALL = SHOW_ALL;
TreeSelect.SHOW_PARENT = SHOW_PARENT;
TreeSelect.SHOW_CHILD = SHOW_CHILD;
export default TreeSelect;
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["children", "value"];
import * as React from 'react';

@@ -17,3 +18,3 @@ import toArray from "rc-util/es/Children/toArray";

value = _node$props.value,
restProps = _objectWithoutProperties(_node$props, ["children", "value"]);
restProps = _objectWithoutProperties(_node$props, _excluded);

@@ -20,0 +21,0 @@ var data = _objectSpread({

import * as React from 'react';
import type { IconType } from 'rc-tree/lib/interface';
import type { Key, LegacyDataNode } from './interface';
import type { FlattenDataNode, Key, LegacyDataNode, RawValueType } from './interface';
import type { SkipType } from './hooks/useKeyValueMapping';
interface ContextProps {

@@ -21,4 +22,6 @@ checkable: boolean | React.ReactNode;

onTreeLoad: (loadedKeys: Key[]) => void;
getEntityByKey: (key: Key, skipType?: SkipType, ignoreDisabledCheck?: boolean) => FlattenDataNode;
getEntityByValue: (value: RawValueType, skipType?: SkipType, ignoreDisabledCheck?: boolean) => FlattenDataNode;
}
export declare const SelectContext: React.Context<ContextProps>;
export {};
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -22,2 +22,3 @@ value: true

var _excluded = ["key", "value", "children"];
var MAX_WARNING_TIMES = 10;

@@ -70,3 +71,3 @@

children = node.children,
rest = (0, _objectWithoutProperties2.default)(node, ["key", "value", "children"]);
rest = (0, _objectWithoutProperties2.default)(node, _excluded);
var mergedValue = 'value' in node ? value : key;

@@ -73,0 +74,0 @@ var dataNode = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, rest), {}, {

@@ -28,6 +28,2 @@ "use strict";

var _useKeyValueMapping3 = _interopRequireDefault(require("./hooks/useKeyValueMapping"));
var _useKeyValueMap3 = _interopRequireDefault(require("./hooks/useKeyValueMap"));
var HIDDEN_STYLE = {

@@ -75,3 +71,5 @@ width: 0,

treeMotion = _React$useContext.treeMotion,
onTreeLoad = _React$useContext.onTreeLoad;
onTreeLoad = _React$useContext.onTreeLoad,
getEntityByKey = _React$useContext.getEntityByKey,
getEntityByValue = _React$useContext.getEntityByValue;

@@ -83,15 +81,4 @@ var treeRef = React.useRef();

return next[0] && prev[1] !== next[1];
});
}); // ========================== Values ==========================
var _useKeyValueMap = (0, _useKeyValueMap3.default)(flattenOptions),
_useKeyValueMap2 = (0, _slicedToArray2.default)(_useKeyValueMap, 2),
cacheKeyMap = _useKeyValueMap2[0],
cacheValueMap = _useKeyValueMap2[1];
var _useKeyValueMapping = (0, _useKeyValueMapping3.default)(cacheKeyMap, cacheValueMap),
_useKeyValueMapping2 = (0, _slicedToArray2.default)(_useKeyValueMapping, 2),
getEntityByKey = _useKeyValueMapping2[0],
getEntityByValue = _useKeyValueMapping2[1]; // ========================== Values ==========================
var valueKeys = React.useMemo(function () {

@@ -98,0 +85,0 @@ return checkedKeys.map(function (val) {

@@ -1,61 +0,67 @@

import * as React from 'react';
import type { SelectProps, RefSelectProps } from 'rc-select/lib/generate';
import type { IconType } from 'rc-tree/lib/interface';
import type { FilterFunc } from 'rc-select/lib/interface/generator';
import type { Key, DefaultValueType, DataNode, LabelValueType, SimpleModeConfig, ChangeEventExtra, LegacyDataNode } from './interface';
import type { CheckedStrategy } from './utils/strategyUtil';
import { SHOW_ALL, SHOW_PARENT, SHOW_CHILD } from './utils/strategyUtil';
export interface TreeSelectProps<ValueType = DefaultValueType> extends Omit<SelectProps<DataNode[], ValueType>, 'onChange' | 'mode' | 'menuItemSelectedIcon' | 'dropdownAlign' | 'backfill' | 'getInputElement' | 'optionLabelProp' | 'tokenSeparators' | 'filterOption'> {
multiple?: boolean;
showArrow?: boolean;
showSearch?: boolean;
open?: boolean;
defaultOpen?: boolean;
value?: ValueType;
defaultValue?: ValueType;
disabled?: boolean;
placeholder?: React.ReactNode;
/** @deprecated Use `searchValue` instead */
inputValue?: string;
searchValue?: string;
autoClearSearchValue?: boolean;
maxTagPlaceholder?: (omittedValues: LabelValueType[]) => React.ReactNode;
loadData?: (dataNode: LegacyDataNode) => Promise<unknown>;
treeNodeFilterProp?: string;
treeNodeLabelProp?: string;
treeDataSimpleMode?: boolean | SimpleModeConfig;
treeExpandedKeys?: Key[];
treeDefaultExpandedKeys?: Key[];
treeLoadedKeys?: Key[];
treeCheckable?: boolean | React.ReactNode;
treeCheckStrictly?: boolean;
showCheckedStrategy?: CheckedStrategy;
treeDefaultExpandAll?: boolean;
treeData?: DataNode[];
treeLine?: boolean;
treeIcon?: IconType;
showTreeIcon?: boolean;
switcherIcon?: IconType;
treeMotion?: any;
children?: React.ReactNode;
filterTreeNode?: boolean | FilterFunc<LegacyDataNode>;
dropdownPopupAlign?: any;
onSearch?: (value: string) => void;
onChange?: (value: ValueType, labelList: React.ReactNode[], extra: ChangeEventExtra) => void;
onTreeExpand?: (expandedKeys: Key[]) => void;
onTreeLoad?: (loadedKeys: Key[]) => void;
onDropdownVisibleChange?: (open: boolean) => void;
/** `searchPlaceholder` has been removed since search box has been merged into input box */
searchPlaceholder?: React.ReactNode;
}
declare class TreeSelect<ValueType = DefaultValueType> extends React.Component<TreeSelectProps<ValueType>, {}> {
static TreeNode: React.FC<import("./TreeNode").TreeNodeProps>;
static SHOW_ALL: typeof SHOW_ALL;
static SHOW_PARENT: typeof SHOW_PARENT;
static SHOW_CHILD: typeof SHOW_CHILD;
selectRef: React.RefObject<RefSelectProps>;
focus: () => void;
blur: () => void;
render(): JSX.Element;
}
/// <reference types="react" />
import { TreeSelectProps } from './generate';
declare const TreeSelect: {
new <ValueType = import("./interface").DefaultValueType>(props: TreeSelectProps<ValueType> | Readonly<TreeSelectProps<ValueType>>): {
selectRef: import("react").RefObject<import("rc-select/lib/generate").RefSelectProps>;
focus: () => void;
blur: () => void;
render(): JSX.Element;
context: any;
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<TreeSelectProps<ValueType>>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: () => void): void;
forceUpdate(callback?: () => void): void;
readonly props: Readonly<TreeSelectProps<ValueType>> & Readonly<{
children?: import("react").ReactNode;
}>;
state: Readonly<{}>;
refs: {
[key: string]: import("react").ReactInstance;
};
componentDidMount?(): void;
shouldComponentUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): boolean;
componentWillUnmount?(): void;
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
getSnapshotBeforeUpdate?(prevProps: Readonly<TreeSelectProps<ValueType>>, prevState: Readonly<{}>): any;
componentDidUpdate?(prevProps: Readonly<TreeSelectProps<ValueType>>, prevState: Readonly<{}>, snapshot?: any): void;
componentWillMount?(): void;
UNSAFE_componentWillMount?(): void;
componentWillReceiveProps?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextContext: any): void;
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextContext: any): void;
componentWillUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): void;
UNSAFE_componentWillUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): void;
};
new <ValueType = import("./interface").DefaultValueType>(props: TreeSelectProps<ValueType>, context: any): {
selectRef: import("react").RefObject<import("rc-select/lib/generate").RefSelectProps>;
focus: () => void;
blur: () => void;
render(): JSX.Element;
context: any;
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<TreeSelectProps<ValueType>>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: () => void): void;
forceUpdate(callback?: () => void): void;
readonly props: Readonly<TreeSelectProps<ValueType>> & Readonly<{
children?: import("react").ReactNode;
}>;
state: Readonly<{}>;
refs: {
[key: string]: import("react").ReactInstance;
};
componentDidMount?(): void;
shouldComponentUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): boolean;
componentWillUnmount?(): void;
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
getSnapshotBeforeUpdate?(prevProps: Readonly<TreeSelectProps<ValueType>>, prevState: Readonly<{}>): any;
componentDidUpdate?(prevProps: Readonly<TreeSelectProps<ValueType>>, prevState: Readonly<{}>, snapshot?: any): void;
componentWillMount?(): void;
UNSAFE_componentWillMount?(): void;
componentWillReceiveProps?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextContext: any): void;
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextContext: any): void;
componentWillUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): void;
UNSAFE_componentWillUpdate?(nextProps: Readonly<TreeSelectProps<ValueType>>, nextState: Readonly<{}>, nextContext: any): void;
};
TreeNode: import("react").FC<import("./TreeNode").TreeNodeProps>;
SHOW_ALL: "SHOW_ALL";
SHOW_PARENT: "SHOW_PARENT";
SHOW_CHILD: "SHOW_CHILD";
contextType?: import("react").Context<any>;
};
export { TreeSelectProps };
export default TreeSelect;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

@@ -12,510 +10,11 @@

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _generate = _interopRequireDefault(require("./generate"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var React = _interopRequireWildcard(require("react"));
var _generate = _interopRequireDefault(require("rc-select/lib/generate"));
var _valueUtil = require("rc-select/lib/utils/valueUtil");
var _treeUtil = require("rc-tree/lib/utils/treeUtil");
var _conductUtil = require("rc-tree/lib/utils/conductUtil");
var _generator = require("rc-select/lib/interface/generator");
var _useMergedState3 = _interopRequireDefault(require("rc-util/lib/hooks/useMergedState"));
var _warning = _interopRequireDefault(require("rc-util/lib/warning"));
var _OptionList = _interopRequireDefault(require("./OptionList"));
var _TreeNode = _interopRequireDefault(require("./TreeNode"));
var _valueUtil2 = require("./utils/valueUtil");
var _warningPropsUtil = _interopRequireDefault(require("./utils/warningPropsUtil"));
var _Context = require("./Context");
var _useTreeData = _interopRequireDefault(require("./hooks/useTreeData"));
var _useKeyValueMap3 = _interopRequireDefault(require("./hooks/useKeyValueMap"));
var _useKeyValueMapping3 = _interopRequireDefault(require("./hooks/useKeyValueMapping"));
var _strategyUtil = require("./utils/strategyUtil");
var _legacyUtil = require("./utils/legacyUtil");
var _useSelectValues = _interopRequireDefault(require("./hooks/useSelectValues"));
var OMIT_PROPS = ['expandedKeys', 'treeData', 'treeCheckable', 'showCheckedStrategy', 'searchPlaceholder', 'treeLine', 'treeIcon', 'showTreeIcon', 'switcherIcon', 'treeNodeFilterProp', 'filterTreeNode', 'dropdownPopupAlign', 'treeDefaultExpandAll', 'treeCheckStrictly', 'treeExpandedKeys', 'treeLoadedKeys', 'treeMotion', 'onTreeExpand', 'onTreeLoad', 'loadData', 'treeDataSimpleMode', 'treeNodeLabelProp', 'treeDefaultExpandedKeys'];
var RefSelect = (0, _generate.default)({
var TreeSelect = (0, _generate.default)({
prefixCls: 'rc-tree-select',
components: {
optionList: _OptionList.default
},
// Not use generate since we will handle ourself
convertChildrenToData: function convertChildrenToData() {
return null;
},
flattenOptions: _valueUtil2.flattenOptions,
// Handle `optionLabelProp` in TreeSelect component
getLabeledValue: _valueUtil.getLabeledValue,
filterOptions: _valueUtil2.filterOptions,
isValueDisabled: _valueUtil2.isValueDisabled,
findValueOption: _valueUtil2.findValueOption,
omitDOMProps: function omitDOMProps(props) {
var cloneProps = (0, _objectSpread2.default)({}, props);
OMIT_PROPS.forEach(function (prop) {
delete cloneProps[prop];
});
return cloneProps;
}
optionList: _OptionList.default
});
RefSelect.displayName = 'Select';
var RefTreeSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
var multiple = props.multiple,
treeCheckable = props.treeCheckable,
treeCheckStrictly = props.treeCheckStrictly,
_props$showCheckedStr = props.showCheckedStrategy,
showCheckedStrategy = _props$showCheckedStr === void 0 ? 'SHOW_CHILD' : _props$showCheckedStr,
labelInValue = props.labelInValue,
loadData = props.loadData,
treeLoadedKeys = props.treeLoadedKeys,
_props$treeNodeFilter = props.treeNodeFilterProp,
treeNodeFilterProp = _props$treeNodeFilter === void 0 ? 'value' : _props$treeNodeFilter,
treeNodeLabelProp = props.treeNodeLabelProp,
treeDataSimpleMode = props.treeDataSimpleMode,
treeData = props.treeData,
treeExpandedKeys = props.treeExpandedKeys,
treeDefaultExpandedKeys = props.treeDefaultExpandedKeys,
treeDefaultExpandAll = props.treeDefaultExpandAll,
children = props.children,
treeIcon = props.treeIcon,
showTreeIcon = props.showTreeIcon,
switcherIcon = props.switcherIcon,
treeLine = props.treeLine,
treeMotion = props.treeMotion,
filterTreeNode = props.filterTreeNode,
dropdownPopupAlign = props.dropdownPopupAlign,
onChange = props.onChange,
onTreeExpand = props.onTreeExpand,
onTreeLoad = props.onTreeLoad,
onDropdownVisibleChange = props.onDropdownVisibleChange,
onSelect = props.onSelect,
onDeselect = props.onDeselect;
var mergedCheckable = treeCheckable || treeCheckStrictly;
var mergedMultiple = multiple || mergedCheckable;
var treeConduction = treeCheckable && !treeCheckStrictly;
var mergedLabelInValue = treeCheckStrictly || labelInValue; // ========================== Ref ==========================
var selectRef = React.useRef(null);
React.useImperativeHandle(ref, function () {
return {
scrollTo: selectRef.current.scrollTo,
focus: selectRef.current.focus,
blur: selectRef.current.blur
};
}); // ======================= Tree Data =======================
// Legacy both support `label` or `title` if not set.
// We have to fallback to function to handle this
var getTreeNodeTitle = function getTreeNodeTitle(node) {
if (!treeData) {
return node.title;
}
return node.label || node.title;
};
var getTreeNodeLabelProp = function getTreeNodeLabelProp(node) {
if (treeNodeLabelProp) {
return node[treeNodeLabelProp];
}
return getTreeNodeTitle(node);
};
var mergedTreeData = (0, _useTreeData.default)(treeData, children, {
getLabelProp: getTreeNodeTitle,
simpleMode: treeDataSimpleMode
});
var flattedOptions = (0, React.useMemo)(function () {
return (0, _valueUtil2.flattenOptions)(mergedTreeData);
}, [mergedTreeData]);
var _useKeyValueMap = (0, _useKeyValueMap3.default)(flattedOptions),
_useKeyValueMap2 = (0, _slicedToArray2.default)(_useKeyValueMap, 2),
cacheKeyMap = _useKeyValueMap2[0],
cacheValueMap = _useKeyValueMap2[1];
var _useKeyValueMapping = (0, _useKeyValueMapping3.default)(cacheKeyMap, cacheValueMap),
_useKeyValueMapping2 = (0, _slicedToArray2.default)(_useKeyValueMapping, 2),
getEntityByKey = _useKeyValueMapping2[0],
getEntityByValue = _useKeyValueMapping2[1]; // Only generate keyEntities for check conduction when is `treeCheckable`
var _useMemo = (0, React.useMemo)(function () {
if (treeConduction) {
return (0, _treeUtil.convertDataToEntities)(mergedTreeData);
}
return {
keyEntities: null
};
}, [mergedTreeData, treeCheckable, treeCheckStrictly]),
conductKeyEntities = _useMemo.keyEntities; // ========================= Value =========================
var _useMergedState = (0, _useMergedState3.default)(props.defaultValue, {
value: props.value
}),
_useMergedState2 = (0, _slicedToArray2.default)(_useMergedState, 2),
value = _useMergedState2[0],
setValue = _useMergedState2[1];
/** Get `missingRawValues` which not exist in the tree yet */
var splitRawValues = function splitRawValues(newRawValues) {
var missingRawValues = [];
var existRawValues = []; // Keep missing value in the cache
newRawValues.forEach(function (val) {
if (getEntityByValue(val)) {
existRawValues.push(val);
} else {
missingRawValues.push(val);
}
});
return {
missingRawValues: missingRawValues,
existRawValues: existRawValues
};
};
var _useMemo2 = (0, React.useMemo)(function () {
var valueHalfCheckedKeys = [];
var newRawValues = [];
(0, _valueUtil2.toArray)(value).forEach(function (item) {
if (item && (0, _typeof2.default)(item) === 'object' && 'value' in item) {
if (item.halfChecked && treeCheckStrictly) {
var entity = getEntityByValue(item.value);
valueHalfCheckedKeys.push(entity ? entity.key : item.value);
} else {
newRawValues.push(item.value);
}
} else {
newRawValues.push(item);
}
}); // We need do conduction of values
if (treeConduction) {
var _splitRawValues = splitRawValues(newRawValues),
missingRawValues = _splitRawValues.missingRawValues,
existRawValues = _splitRawValues.existRawValues;
var keyList = existRawValues.map(function (val) {
return getEntityByValue(val).key;
});
var _conductCheck = (0, _conductUtil.conductCheck)(keyList, true, conductKeyEntities),
checkedKeys = _conductCheck.checkedKeys,
halfCheckedKeys = _conductCheck.halfCheckedKeys;
return [[].concat((0, _toConsumableArray2.default)(missingRawValues), (0, _toConsumableArray2.default)(checkedKeys.map(function (key) {
return getEntityByKey(key).data.value;
}))), halfCheckedKeys];
}
return [newRawValues, valueHalfCheckedKeys];
}, [value, mergedMultiple, mergedLabelInValue, treeCheckable, treeCheckStrictly]),
_useMemo3 = (0, _slicedToArray2.default)(_useMemo2, 2),
rawValues = _useMemo3[0],
rawHalfCheckedKeys = _useMemo3[1];
var selectValues = (0, _useSelectValues.default)(rawValues, {
treeConduction: treeConduction,
value: value,
showCheckedStrategy: showCheckedStrategy,
conductKeyEntities: conductKeyEntities,
getEntityByValue: getEntityByValue,
getEntityByKey: getEntityByKey,
getLabelProp: getTreeNodeLabelProp
});
var triggerChange = function triggerChange(newRawValues, extra, source) {
setValue(mergedMultiple ? newRawValues : newRawValues[0]);
if (onChange) {
var eventValues = newRawValues;
if (treeConduction && showCheckedStrategy !== 'SHOW_ALL') {
var keyList = newRawValues.map(function (val) {
var entity = getEntityByValue(val);
return entity ? entity.key : val;
});
var formattedKeyList = (0, _strategyUtil.formatStrategyKeys)(keyList, showCheckedStrategy, conductKeyEntities);
eventValues = formattedKeyList.map(function (key) {
var entity = getEntityByKey(key);
return entity ? entity.data.value : key;
});
}
var _ref = extra || {
triggerValue: undefined,
selected: undefined
},
triggerValue = _ref.triggerValue,
selected = _ref.selected;
var returnValues = mergedLabelInValue ? (0, _valueUtil2.getRawValueLabeled)(eventValues, value, getEntityByValue, getTreeNodeLabelProp) : eventValues; // We need fill half check back
if (treeCheckStrictly) {
var halfValues = rawHalfCheckedKeys.map(function (key) {
var entity = getEntityByKey(key);
return entity ? entity.data.value : key;
}).filter(function (val) {
return !eventValues.includes(val);
});
returnValues = [].concat((0, _toConsumableArray2.default)(returnValues), (0, _toConsumableArray2.default)((0, _valueUtil2.getRawValueLabeled)(halfValues, value, getEntityByValue, getTreeNodeLabelProp)));
}
var additionalInfo = {
// [Legacy] Always return as array contains label & value
preValue: selectValues,
triggerValue: triggerValue
}; // [Legacy] Fill legacy data if user query.
// This is expansive that we only fill when user query
// https://github.com/react-component/tree-select/blob/fe33eb7c27830c9ac70cd1fdb1ebbe7bc679c16a/src/Select.jsx
var showPosition = true;
if (treeCheckStrictly || source === 'selection' && !selected) {
showPosition = false;
}
(0, _legacyUtil.fillAdditionalInfo)(additionalInfo, triggerValue, newRawValues, mergedTreeData, showPosition);
if (mergedCheckable) {
additionalInfo.checked = selected;
} else {
additionalInfo.selected = selected;
}
onChange(mergedMultiple ? returnValues : returnValues[0], mergedLabelInValue ? null : eventValues.map(function (val) {
var entity = getEntityByValue(val);
return entity ? getTreeNodeLabelProp(entity.data) : null;
}), additionalInfo);
}
};
var onInternalSelect = function onInternalSelect(selectValue, option, source) {
var eventValue = mergedLabelInValue ? selectValue : selectValue;
if (!mergedMultiple) {
// Single mode always set value
triggerChange([selectValue], {
selected: true,
triggerValue: selectValue
}, source);
} else {
var newRawValues = (0, _valueUtil2.addValue)(rawValues, selectValue); // Add keys if tree conduction
if (treeConduction) {
// Should keep missing values
var _splitRawValues2 = splitRawValues(newRawValues),
missingRawValues = _splitRawValues2.missingRawValues,
existRawValues = _splitRawValues2.existRawValues;
var keyList = existRawValues.map(function (val) {
return getEntityByValue(val).key;
});
var _conductCheck2 = (0, _conductUtil.conductCheck)(keyList, true, conductKeyEntities),
checkedKeys = _conductCheck2.checkedKeys;
newRawValues = [].concat((0, _toConsumableArray2.default)(missingRawValues), (0, _toConsumableArray2.default)(checkedKeys.map(function (key) {
return getEntityByKey(key).data.value;
})));
}
triggerChange(newRawValues, {
selected: true,
triggerValue: selectValue
}, source);
}
if (onSelect) {
onSelect(eventValue, option);
}
};
var onInternalDeselect = function onInternalDeselect(selectValue, option, source) {
var eventValue = mergedLabelInValue ? selectValue : selectValue;
var newRawValues = (0, _valueUtil2.removeValue)(rawValues, selectValue); // Remove keys if tree conduction
if (treeConduction) {
var _splitRawValues3 = splitRawValues(newRawValues),
missingRawValues = _splitRawValues3.missingRawValues,
existRawValues = _splitRawValues3.existRawValues;
var keyList = existRawValues.map(function (val) {
return getEntityByValue(val).key;
});
var _conductCheck3 = (0, _conductUtil.conductCheck)(keyList, {
checked: false,
halfCheckedKeys: rawHalfCheckedKeys
}, conductKeyEntities),
checkedKeys = _conductCheck3.checkedKeys;
newRawValues = [].concat((0, _toConsumableArray2.default)(missingRawValues), (0, _toConsumableArray2.default)(checkedKeys.map(function (key) {
return getEntityByKey(key).data.value;
})));
}
triggerChange(newRawValues, {
selected: false,
triggerValue: selectValue
}, source);
if (onDeselect) {
onDeselect(eventValue, option);
}
};
var onInternalClear = function onInternalClear() {
triggerChange([], null, 'clear');
}; // ========================= Open ==========================
var onInternalDropdownVisibleChange = React.useCallback(function (open) {
if (onDropdownVisibleChange) {
var legacyParam = {};
Object.defineProperty(legacyParam, 'documentClickClose', {
get: function get() {
(0, _warning.default)(false, 'Second param of `onDropdownVisibleChange` has been removed.');
return false;
}
});
onDropdownVisibleChange(open, legacyParam);
}
}, [onDropdownVisibleChange]); // ======================== Warning ========================
if (process.env.NODE_ENV !== 'production') {
(0, _warningPropsUtil.default)(props);
} // ======================== Render =========================
// We pass some props into select props style
var selectProps = {
optionLabelProp: null,
optionFilterProp: treeNodeFilterProp,
dropdownAlign: dropdownPopupAlign,
internalProps: {
mark: _generator.INTERNAL_PROPS_MARK,
onClear: onInternalClear,
skipTriggerChange: true,
skipTriggerSelect: true,
onRawSelect: onInternalSelect,
onRawDeselect: onInternalDeselect
}
};
if ('filterTreeNode' in props) {
selectProps.filterOption = filterTreeNode;
}
return /*#__PURE__*/React.createElement(_Context.SelectContext.Provider, {
value: {
checkable: mergedCheckable,
loadData: loadData,
treeLoadedKeys: treeLoadedKeys,
onTreeLoad: onTreeLoad,
checkedKeys: rawValues,
halfCheckedKeys: rawHalfCheckedKeys,
treeDefaultExpandAll: treeDefaultExpandAll,
treeExpandedKeys: treeExpandedKeys,
treeDefaultExpandedKeys: treeDefaultExpandedKeys,
onTreeExpand: onTreeExpand,
treeIcon: treeIcon,
treeMotion: treeMotion,
showTreeIcon: showTreeIcon,
switcherIcon: switcherIcon,
treeLine: treeLine,
treeNodeFilterProp: treeNodeFilterProp
}
}, /*#__PURE__*/React.createElement(RefSelect, (0, _extends2.default)({
ref: selectRef,
mode: mergedMultiple ? 'multiple' : null
}, props, selectProps, {
value: selectValues // We will handle this ourself since we need calculate conduction
,
labelInValue: true,
options: mergedTreeData,
onChange: null,
onSelect: null,
onDeselect: null,
onDropdownVisibleChange: onInternalDropdownVisibleChange
})));
}); // Use class component since typescript not support generic
// by `forwardRef` with function component yet.
var TreeSelect = /*#__PURE__*/function (_React$Component) {
(0, _inherits2.default)(TreeSelect, _React$Component);
var _super = (0, _createSuper2.default)(TreeSelect);
function TreeSelect() {
var _this;
(0, _classCallCheck2.default)(this, TreeSelect);
_this = _super.apply(this, arguments);
_this.selectRef = /*#__PURE__*/React.createRef();
_this.focus = function () {
_this.selectRef.current.focus();
};
_this.blur = function () {
_this.selectRef.current.blur();
};
return _this;
}
(0, _createClass2.default)(TreeSelect, [{
key: "render",
value: function render() {
return /*#__PURE__*/React.createElement(RefTreeSelect, (0, _extends2.default)({
ref: this.selectRef
}, this.props));
}
}]);
return TreeSelect;
}(React.Component);
TreeSelect.TreeNode = _TreeNode.default;
TreeSelect.SHOW_ALL = _strategyUtil.SHOW_ALL;
TreeSelect.SHOW_PARENT = _strategyUtil.SHOW_PARENT;
TreeSelect.SHOW_CHILD = _strategyUtil.SHOW_CHILD;
var _default = TreeSelect;
exports.default = _default;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -26,2 +26,4 @@ value: true

var _excluded = ["children", "value"];
function convertChildrenToData(nodes) {

@@ -37,3 +39,3 @@ return (0, _toArray.default)(nodes).map(function (node) {

value = _node$props.value,
restProps = (0, _objectWithoutProperties2.default)(_node$props, ["children", "value"]);
restProps = (0, _objectWithoutProperties2.default)(_node$props, _excluded);
var data = (0, _objectSpread2.default)({

@@ -40,0 +42,0 @@ key: key,

{
"name": "rc-tree-select",
"version": "4.3.3",
"version": "4.4.0-alpha.0",
"description": "tree-select ui component for react",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc