UNPKG

amis-model-design

Version:

amis模型设计器

165 lines (164 loc) 7.75 kB
import type { ClassNamesFn, RenderOptions, Schema } from 'amis-core'; import { DataSourceItem, DBTable, FieldItem, FieldType, FormSchema, ModelItem, RelationShipItem } from '../type'; import { EventContext, EventEmitter, PluginEvent, PluginEventListener } from './Event'; import { PluginInterface, BuildFieldSchemaContext, BuildFieldSchemaContextOthers } from './PluginInterface'; import { MainStore } from './MainStore'; import { ZoomPan } from './ZoomPan'; import { ApiStrategyInterface, Strategy } from '../schema-builder/ApiStrategyInterface'; import { ApiBuilder } from '../schema-builder/ApiBuilder'; import { SharedContext } from '../schema-builder/SharedContext'; export interface PluginClass { new (manager: Manager): PluginInterface; id: string; order?: number; } export declare function addPlugin(factory: PluginClass): void; export declare function removePlugin(name: string): void; export declare function getPlugins(): PluginClass[]; export interface ManagerOptions extends PluginEventListener { /** * 如果配置了,组件内渲染 amis schema 共享此 env */ env?: RenderOptions; /** * 插件黑名单 */ disablePluginList?: Array<string> | ((id: string, plugin: PluginClass) => boolean); /** * 外部插件 */ plugins?: Array<PluginClass>; apiStrategy?: Strategy; apiStrategyOptions?: { apiPrefix?: string; /** * 是有生成 model 协议地址,如 model://dsKey.key */ useApiSchema?: boolean; }; /** * 系统字段映射如 * * { * 'createdAt': 'created_at', * 'updatedAt': 'updated_at', * 'deletedAt': 'deleted_at' * 'createdBy': 'created_by', * 'updatedBy': 'updated_by', * 'deletedBy': 'deleted_by' * } */ systemFieldKeyMap?: Record<string, string>; /** * 根据数据源获取数据库表列表 */ onFetchDBTableList?: (datasource: DataSourceItem) => Promise<string[]>; /** * 根据数据表简要以及数据源获取数据表详情 */ onFetchDBTableDetail?: (name: string, datasource: DataSourceItem) => Promise<DBTable>; /** * 获取数据源列表 * @returns */ onFetchSourceList?: () => Promise<Array<DataSourceItem>>; /** * 获取数据源详情 * @returns */ onFetchSource?: (id: string | number) => Promise<DataSourceItem>; /** * 根据数据源获取模型列表 * @param datasource * @returns */ onFetchModelList?: (datasource: DataSourceItem) => Promise<Array<ModelItem>>; } export declare const ManagerOptionsKeys: string[]; export declare class Manager extends EventEmitter { readonly options: ManagerOptions; readonly plugins: Array<PluginInterface>; readonly env: RenderOptions; readonly classnames: ClassNamesFn; readonly store: MainStore; readonly pan: ZoomPan; static defaultOptions: Partial<ManagerOptions>; static setDefaultOptions(options: Partial<ManagerOptions>): void; static shared: Manager | null; static createSharedInstance(options?: ManagerOptions): void; static create(options?: ManagerOptions): Manager; disabled: boolean; id: string; toDispose: Array<() => void>; constructor(options?: ManagerOptions); getDialectType(type: string): (import("../type").DatabaseDialectType & { plugin: PluginInterface; }) | undefined; getFieldType(type: string): (FieldType & { plugin: PluginInterface; }) | undefined; getRelationType(type: string): (import("../type").RelationType & { plugin: PluginInterface; }) | undefined; /** * 派发事件。 * @param type * @param context */ trigger<T extends EventContext>(type: string, context: T): PluginEvent<T>; setDatasource(value: DataSourceItem): void; setModels(values: ModelItem[]): void; validate(errors?: Array<string>, models?: ModelItem[]): false | Promise<boolean>; makeSchemaBuilder(modelKey: string, kind: string, options?: { apiPrefix?: string; /** * 是有生成 model 协议地址,如 model://dsKey.key */ useApiSchema?: boolean; strategy?: Strategy; }, sharedContext?: SharedContext): import("../schema-builder/SchemaBuilder").SchemaBuilderInterface<any>; makeApiStrategy(modelKey: string, apiStrategyOptions: any, strategy?: Strategy | undefined): ApiStrategyInterface; guessFieldOptionsFromSchema(model: ModelItem, field: FieldItem, others?: BuildFieldSchemaContextOthers, schema?: any, options?: any): Promise<any>; buildFieldSettingForm(model: ModelItem, field: FieldItem, others?: BuildFieldSchemaContextOthers, options?: any, schema?: FormSchema): Promise<FormSchema | undefined>; buildFieldSchema(model: ModelItem, field: FieldItem, others?: BuildFieldSchemaContextOthers, options?: any, ab?: ApiBuilder, schema?: Schema, originSchema?: any): Promise<Schema | undefined>; buildFieldViewSettingForm(model: ModelItem, field: FieldItem, others?: BuildFieldSchemaContextOthers, schema?: FormSchema): Promise<FormSchema | undefined>; buildFieldViewSchema(model: ModelItem, field: FieldItem, others?: BuildFieldSchemaContextOthers, options?: any, ab?: ApiBuilder, schema?: Schema): Promise<Schema | undefined>; buildFieldEditSettingForm(model: ModelItem, field: FieldItem, others?: BuildFieldSchemaContextOthers, schema?: FormSchema): Promise<FormSchema | undefined>; buildFieldEditSchema(model: ModelItem, field: FieldItem, others?: BuildFieldSchemaContextOthers, options?: any, ab?: ApiBuilder, schema?: Schema): Promise<Schema | undefined>; buildFieldFilterSettingForm(model: ModelItem, field: FieldItem, others?: BuildFieldSchemaContextOthers, schema?: FormSchema): Promise<FormSchema | undefined>; buildFieldFilterSchema(model: ModelItem, field: FieldItem, others?: BuildFieldSchemaContextOthers, options?: any, ab?: ApiBuilder, schema?: Schema): Promise<Schema | undefined>; buildFieldConditionFieldConfig(model: ModelItem, field: FieldItem, schema?: Schema): Promise<Schema | undefined>; /** * 构建 FX 变量 * * @returns 返回一个 Promise,其中包含一个数组类型的变量集合。 */ buildFXVariables(): Promise<any>; protected makeBuildFieldSchemaContext(model: ModelItem, field: FieldItem, others?: BuildFieldSchemaContextOthers): BuildFieldSchemaContext; hooksCache: any; callHook(id: keyof ManagerOptions, args?: Array<any>): any; handleAddField(item: ModelItem): Promise<void>; handleAddFieldValidate(errors: any, data: { items: ModelItem[]; }): void; handleAddFieldConfirm(value: FieldItem[]): Promise<void>; handleAddFieldCancel(): void; handleAddRelation(item: ModelItem): void; handleAddRelationConfirm(value: any): Promise<void>; handleAddRelationCancel(): void; removeField(model: ModelItem, field: FieldItem): void; removeRelation(model: ModelItem, relation: RelationShipItem): void; handleModelSelect(item: ModelItem): void; handleModelFormChange(value: any): void; removeModel(item: ModelItem): Promise<void>; handleModelFieldEdit(model: ModelItem, modelIndex: number, field: FieldItem, index: number): Promise<void>; handleModelFormFieldValidate(value: FieldItem | RelationShipItem): any; handleModelFormFieldChange(value: FieldItem | RelationShipItem): void; buildAddModelForm(): void; addModel(value: ModelItem): void; updateModal(value: ModelItem): void; buildEditDatasourceForm(options: any, defaultValues?: {}): void; layerRef(ref: HTMLDivElement | null): void; clearHookCache(key?: string): void; dispose(): void; }