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,131 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.convertChildrenToData = convertChildrenToData;
exports.fillAdditionalInfo = fillAdditionalInfo;
exports.fillLegacyProps = fillLegacyProps;
var React = _interopRequireWildcard(require("react"));
var _toArray = _interopRequireDefault(require("@rc-component/util/lib/Children/toArray"));
var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning"));
var _TreeNode = _interopRequireDefault(require("../TreeNode"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function convertChildrenToData(nodes) {
return (0, _toArray.default)(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);
}
function fillLegacyProps(dataNode) {
if (!dataNode) {
return dataNode;
}
const cloneNode = {
...dataNode
};
if (!('props' in cloneNode)) {
Object.defineProperty(cloneNode, 'props', {
get() {
(0, _warning.default)(false, 'New `rc-tree-select` not support return node instance as argument anymore. Please consider to remove `props` access.');
return cloneNode;
}
});
}
return cloneNode;
}
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.default, 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() {
(0, _warning.default)(false, '`triggerNode` is deprecated. Please consider decoupling data with node.');
generateMap();
return triggerNode;
}
});
Object.defineProperty(extra, 'allCheckedNodes', {
get() {
(0, _warning.default)(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,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SHOW_PARENT = exports.SHOW_CHILD = exports.SHOW_ALL = void 0;
exports.formatStrategyValues = formatStrategyValues;
var _valueUtil = require("./valueUtil");
const SHOW_ALL = exports.SHOW_ALL = 'SHOW_ALL';
const SHOW_PARENT = exports.SHOW_PARENT = 'SHOW_PARENT';
const SHOW_CHILD = exports.SHOW_CHILD = 'SHOW_CHILD';
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
}) => (0, _valueUtil.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 || (0, _valueUtil.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,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.toArray = exports.isNil = exports.isCheckDisabled = exports.getAllKeys = exports.fillFieldNames = void 0;
const toArray = value => Array.isArray(value) ? value : value !== undefined ? [value] : [];
exports.toArray = toArray;
const fillFieldNames = fieldNames => {
const {
label,
value,
children
} = fieldNames || {};
return {
_title: label ? [label] : ['title', 'label'],
value: value || 'value',
key: value || 'value',
children: children || 'children'
};
};
exports.fillFieldNames = fillFieldNames;
const isCheckDisabled = node => !node || node.disabled || node.disableCheckbox || node.checkable === false;
exports.isCheckDisabled = isCheckDisabled;
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;
};
exports.getAllKeys = getAllKeys;
const isNil = val => val === null || val === undefined;
exports.isNil = isNil;
@@ -0,0 +1,5 @@
import type { TreeSelectProps } from '../TreeSelect';
declare function warningProps(props: TreeSelectProps & {
searchPlaceholder?: string;
}): void;
export default warningProps;
@@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning"));
var _valueUtil = require("./valueUtil");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function warningProps(props) {
const {
searchPlaceholder,
treeCheckStrictly,
treeCheckable,
labelInValue,
value,
multiple,
showCheckedStrategy,
maxCount
} = props;
(0, _warning.default)(!searchPlaceholder, '`searchPlaceholder` has been removed.');
if (treeCheckStrictly && labelInValue === false) {
(0, _warning.default)(false, '`treeCheckStrictly` will force set `labelInValue` to `true`.');
}
if (labelInValue || treeCheckStrictly) {
(0, _warning.default)((0, _valueUtil.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) {
(0, _warning.default)(!value || Array.isArray(value), '`value` should be an array when `TreeSelect` is checkable or multiple.');
} else {
(0, _warning.default)(!Array.isArray(value), '`value` should not be array when `TreeSelect` is single mode.');
}
if (maxCount && (showCheckedStrategy === 'SHOW_ALL' && !treeCheckStrictly || showCheckedStrategy === 'SHOW_PARENT')) {
(0, _warning.default)(false, '`maxCount` not work with `showCheckedStrategy=SHOW_ALL` (when `treeCheckStrictly=false`) or `showCheckedStrategy=SHOW_PARENT`.');
}
}
var _default = exports.default = warningProps;