This commit is contained in:
2026-05-25 17:08:18 +08:00
parent df501f6151
commit f1259b71b5
9178 changed files with 1626125 additions and 0 deletions
@@ -0,0 +1,5 @@
import * as React from 'react';
import type { DataNode, ChangeEventExtra, SafeKey, FieldNames } from '../interface';
export declare function convertChildrenToData(nodes: React.ReactNode): DataNode[];
export declare function fillLegacyProps(dataNode: DataNode): DataNode;
export declare function fillAdditionalInfo(extra: ChangeEventExtra, triggerValue: SafeKey, checkedValues: SafeKey[], treeData: DataNode[], showPosition: boolean, fieldNames: FieldNames): void;
@@ -0,0 +1,120 @@
import * as React from 'react';
import toArray from "@rc-component/util/es/Children/toArray";
import warning from "@rc-component/util/es/warning";
import TreeNode from "../TreeNode";
export function convertChildrenToData(nodes) {
return toArray(nodes).map(node => {
if (! /*#__PURE__*/React.isValidElement(node) || !node.type) {
return null;
}
const {
key,
props: {
children,
value,
...restProps
}
} = node;
const data = {
key,
value,
...restProps
};
const childData = convertChildrenToData(children);
if (childData.length) {
data.children = childData;
}
return data;
}).filter(data => data);
}
export function fillLegacyProps(dataNode) {
if (!dataNode) {
return dataNode;
}
const cloneNode = {
...dataNode
};
if (!('props' in cloneNode)) {
Object.defineProperty(cloneNode, 'props', {
get() {
warning(false, 'New `rc-tree-select` not support return node instance as argument anymore. Please consider to remove `props` access.');
return cloneNode;
}
});
}
return cloneNode;
}
export function fillAdditionalInfo(extra, triggerValue, checkedValues, treeData, showPosition, fieldNames) {
let triggerNode = null;
let nodeList = null;
function generateMap() {
function dig(list, level = '0', parentIncluded = false) {
return list.map((option, index) => {
const pos = `${level}-${index}`;
const value = option[fieldNames.value];
const included = checkedValues.includes(value);
const children = dig(option[fieldNames.children] || [], pos, included);
const node = /*#__PURE__*/React.createElement(TreeNode, option, children.map(child => child.node));
// Link with trigger node
if (triggerValue === value) {
triggerNode = node;
}
if (included) {
const checkedNode = {
pos,
node,
children
};
if (!parentIncluded) {
nodeList.push(checkedNode);
}
return checkedNode;
}
return null;
}).filter(node => node);
}
if (!nodeList) {
nodeList = [];
dig(treeData);
// Sort to keep the checked node length
nodeList.sort(({
node: {
props: {
value: val1
}
}
}, {
node: {
props: {
value: val2
}
}
}) => {
const index1 = checkedValues.indexOf(val1);
const index2 = checkedValues.indexOf(val2);
return index1 - index2;
});
}
}
Object.defineProperty(extra, 'triggerNode', {
get() {
warning(false, '`triggerNode` is deprecated. Please consider decoupling data with node.');
generateMap();
return triggerNode;
}
});
Object.defineProperty(extra, 'allCheckedNodes', {
get() {
warning(false, '`allCheckedNodes` is deprecated. Please consider decoupling data with node.');
generateMap();
if (showPosition) {
return nodeList;
}
return nodeList.map(({
node
}) => node);
}
});
}
@@ -0,0 +1,7 @@
import type { DataEntity } from '@rc-component/tree/lib/interface';
import type { SafeKey, FieldNames } from '../interface';
export declare const SHOW_ALL = "SHOW_ALL";
export declare const SHOW_PARENT = "SHOW_PARENT";
export declare const SHOW_CHILD = "SHOW_CHILD";
export type CheckedStrategy = typeof SHOW_ALL | typeof SHOW_PARENT | typeof SHOW_CHILD;
export declare function formatStrategyValues(values: SafeKey[], strategy: CheckedStrategy, keyEntities: Record<SafeKey, DataEntity>, fieldNames: FieldNames): SafeKey[];
@@ -0,0 +1,25 @@
import { isCheckDisabled } from "./valueUtil";
export const SHOW_ALL = 'SHOW_ALL';
export const SHOW_PARENT = 'SHOW_PARENT';
export const SHOW_CHILD = 'SHOW_CHILD';
export function formatStrategyValues(values, strategy, keyEntities, fieldNames) {
const valueSet = new Set(values);
if (strategy === SHOW_CHILD) {
return values.filter(key => {
const entity = keyEntities[key];
return !entity || !entity.children || !entity.children.some(({
node
}) => valueSet.has(node[fieldNames.value])) || !entity.children.every(({
node
}) => isCheckDisabled(node) || valueSet.has(node[fieldNames.value]));
});
}
if (strategy === SHOW_PARENT) {
return values.filter(key => {
const entity = keyEntities[key];
const parent = entity ? entity.parent : null;
return !parent || isCheckDisabled(parent.node) || !valueSet.has(parent.key);
});
}
return values;
}
@@ -0,0 +1,11 @@
import type { DataNode, FieldNames, SafeKey } from '../interface';
export declare const toArray: <T>(value: T | T[]) => T[];
export declare const fillFieldNames: (fieldNames?: FieldNames) => {
_title: string[];
value: string;
key: string;
children: string;
};
export declare const isCheckDisabled: (node: DataNode) => boolean;
export declare const getAllKeys: (treeData: DataNode[], fieldNames: FieldNames) => SafeKey[];
export declare const isNil: (val: any) => boolean;
@@ -0,0 +1,30 @@
export const toArray = value => Array.isArray(value) ? value : value !== undefined ? [value] : [];
export const fillFieldNames = fieldNames => {
const {
label,
value,
children
} = fieldNames || {};
return {
_title: label ? [label] : ['title', 'label'],
value: value || 'value',
key: value || 'value',
children: children || 'children'
};
};
export const isCheckDisabled = node => !node || node.disabled || node.disableCheckbox || node.checkable === false;
export const getAllKeys = (treeData, fieldNames) => {
const keys = [];
const dig = list => {
list.forEach(item => {
const children = item[fieldNames.children];
if (children) {
keys.push(item[fieldNames.value]);
dig(children);
}
});
};
dig(treeData);
return keys;
};
export const isNil = val => val === null || val === undefined;
@@ -0,0 +1,5 @@
import type { TreeSelectProps } from '../TreeSelect';
declare function warningProps(props: TreeSelectProps & {
searchPlaceholder?: string;
}): void;
export default warningProps;
@@ -0,0 +1,30 @@
import warning from "@rc-component/util/es/warning";
import { toArray } from "./valueUtil";
function warningProps(props) {
const {
searchPlaceholder,
treeCheckStrictly,
treeCheckable,
labelInValue,
value,
multiple,
showCheckedStrategy,
maxCount
} = props;
warning(!searchPlaceholder, '`searchPlaceholder` has been removed.');
if (treeCheckStrictly && labelInValue === false) {
warning(false, '`treeCheckStrictly` will force set `labelInValue` to `true`.');
}
if (labelInValue || treeCheckStrictly) {
warning(toArray(value).every(val => val && typeof val === 'object' && 'value' in val), 'Invalid prop `value` supplied to `TreeSelect`. You should use { label: string, value: string | number } or [{ label: string, value: string | number }] instead.');
}
if (treeCheckStrictly || multiple || treeCheckable) {
warning(!value || Array.isArray(value), '`value` should be an array when `TreeSelect` is checkable or multiple.');
} else {
warning(!Array.isArray(value), '`value` should not be array when `TreeSelect` is single mode.');
}
if (maxCount && (showCheckedStrategy === 'SHOW_ALL' && !treeCheckStrictly || showCheckedStrategy === 'SHOW_PARENT')) {
warning(false, '`maxCount` not work with `showCheckedStrategy=SHOW_ALL` (when `treeCheckStrictly=false`) or `showCheckedStrategy=SHOW_PARENT`.');
}
}
export default warningProps;