import React from "react"; import type { DataSourceParams } from "../../../data"; import type { EntityMetadata, RelationMetadata } from "../../../providers"; import type { PropertyEditorProps } from "../../../type"; import "./field-selector.scss"; import { EditorPanelContext } from "../../../context"; interface Props extends PropertyEditorProps { /** 选择模式:multiple 多选 / single 单选,默认 multiple */ type?: "multiple" | "single"; /** 数据源参数,用于取实体类型与数据库名称以加载字段树 */ dataSourceParams?: DataSourceParams; } export interface FieldTreeNode { title: string; value: string; key: string; children?: FieldTreeNode[]; isLeaf?: boolean; /** 以下字段仅供 TreeSelect loadData 懒加载使用,rc-tree 会随节点透传 */ targetEntityType?: string; propPath?: string; visitedKeys?: string[]; depth?: number; } interface State { loading: boolean; treeData?: FieldTreeNode[]; /** 内部统一以 string[] 保存选中键,发射时按 type 收成 string 或 string[] */ value?: string[]; entityType?: string; databaseName?: string; } type TreeSelectValue = string | string[] | undefined; /** * 字段选择器基类(泛型,按 V 区分 string[] 多选 / string 单选): * 按数据源参数中的实体类型加载字段(含关联实体的嵌套字段),以树形呈现, * 实体类型或数据库变化时重新加载。多选/单选由 `type` 控制,值归一化逻辑由 * toInternal / toExternal 完成,TreeSelect 内部始终按 string[] 处理。 */ export declare class FieldSelector extends React.Component, State> { static contextType: React.Context<{ componentData: import("../../..").ComponentData; currentComponentData?: import("../../..").ComponentData; } | undefined>; context: React.ContextType; /** 当前库的实体元数据(来自一次性 getEntityMetadatas),供 loadData 本地懒加载子节点,避免再发 HTTP */ private metadataMap; /** loading 最短展示时长开关:字段树立即写入,只推迟 loading 关闭,保证刷新图标转够时长 */ private loading; constructor(props: Props); /** 将外部值(string 或 string[])归一为内部 string[] */ static toInternal(value: string | string[] | undefined): string[] | undefined; /** 当前是否为多选 */ private get isMultiple(); /** 将内部 string[] 按当前模式收成外部值(string 或 string[]) */ private toExternal; /** 比较两个外部值(string 或 string[])是否等价 */ private isSameExternal; get dataSourceParams(): DataSourceParams | undefined; componentDidUpdate(prevProps: Readonly>): void; loadFields(): void; componentDidMount(): void; componentWillUnmount(): void; /** TreeSelect loadData:展开关联节点时,从本地缓存的 schema 同步构建其子节点(不再发 HTTP) */ private loadData; render(): React.ReactNode; } /** * 字段多选编辑器:fields 属性(string[])。 */ export declare class MultipleFieldSelector extends FieldSelector { static defaultProps: { type: "multiple"; }; } /** * 字段单选编辑器:单个字段(string,支持关联前缀如 customer.name)。 */ export declare class SingleFieldSelector extends FieldSelector { static defaultProps: { type: "single"; }; } export declare function normalizeTreeSelectValue(value: TreeSelectValue): string[] | undefined; export declare function toTreeSelectValue(value: string[] | undefined, multiple?: boolean): TreeSelectValue; /** * 由关联元数据推断目标实体类型名:typeorm 的 RelationMetadata.type 在 0.3 中 * 直接指向目标实体(类名或实体名字符串),据此拼接带数据库前缀的实体类型。 */ export declare function resolveEntityType(relation: RelationMetadata, currentEntityType: string): string | undefined; export declare function isSameValue(left?: string[], right?: string[]): boolean; /** * 按数据源参数加载实体元数据并构建字段树(含关联实体的嵌套字段)。 * 抽成模块级函数供 MultipleFieldSelector / SingleFieldSelector 复用。 */ /** 字段树最大嵌套层级:根实体为第 0 层,超出后关联节点作为叶子不再展开,避免超大树 / 无限递归(③) */ export declare const MAX_FIELD_TREE_DEPTH = 4; /** * 构建单一层级的字段节点(列 + 关联)。关联节点不在此递归展开,而是携带元数据, * 待 TreeSelect 展开时由 loadData 从本地 schema 懒加载其子节点(②); * 达到最大深度时关联节点标记为叶子(③)。 */ export declare function buildFieldTree(entityType: string, databaseName: string | undefined, visitedKeys: string[], metadataMap: Map, propPath?: string, depth?: number): FieldTreeNode[]; export declare function isDataSourceParams(dataSource: DataSourceParams | undefined): boolean; export default MultipleFieldSelector;