import { CSSProperties, Component, DefineComponent, PropType, Slots, VNode, VNodeChild } from 'vue' import { MaybePromise, PartialKeys, useHistoryStack } from '@ithinkdt/common' import { DictItem } from '@ithinkdt/common/dict' import { HttpMethod } from '@ithinkdt/common/request' import { PageResponse } from '@ithinkdt/page' import { type EntityField, EntityFieldType } from './entity.js' export interface BaseState { type: unknown name: string description?: string } export interface VarState extends BaseState { type: 'var' varType?: 'string' | 'number' | 'boolean' | 'custom' defaultValue?: string | number | boolean content?: string resetable?: boolean } export interface FetchState extends BaseState { type: 'fetch' method: HttpMethod api: string params?: string } export interface EntityState extends BaseState { type: 'entity' modelName?: string queryConfig?: Record _modelName?: string autoFetch?: boolean listType?: 'page' | 'list' presets?: ('get' | 'post' | 'put' | 'delete')[] initValue?: { fields?: EntityField[] list?: Record[] modelName?: string loading?: boolean total?: number currentPage?: number pageSize?: number search?: Record sort?: { order?: 'asc' | 'desc', name?: string } } } export interface StateDefinitions { var: VarState fetch: FetchState entity: EntityState } export interface BaseMethod { type: unknown name: string description?: string hidden?: boolean deletable?: boolean } export interface ScriptMethod extends BaseMethod { type: 'script' script: string } export interface MethodDefinitions { script: ScriptMethod } export interface LcNode { id: string type: string label: string props: Record css: string css2: string listeners: [string, string, string[]?][] children: Record hidable?: boolean deletable?: boolean cloneable?: boolean container?: boolean form?: boolean __extra?: Extra } export interface LcSchema { state: StateDefinitions[keyof StateDefinitions][] methods: MethodDefinitions[keyof MethodDefinitions][] name: string tree: LcNode css: string css2: string } type StateType = T extends infer T1 extends keyof StateDefinitions ? LcStateDefinition : never type MethodType = T extends infer T1 extends keyof MethodDefinitions ? LcMethodDefinition : never export interface ProviderDoc { name: string snippet: string description: string | (() => VNodeChild) type: 'const' | 'util' tip?: string | (() => VNodeChild) } export declare class LowcodeEngineCore { providers: Record stateDefinitions: StateType[] state: Record methods: Record void> setSchema(schema: Partial, after?: () => void): Promise defineState( name: string, type: T, config: PartialKeys, ): Promise defineMethod( name: string, type: T, config: PartialKeys, ): Promise<() => void> getFnFromScriptDefault(script: string): Promise<() => void> } export interface LcMaterialPropItem { label: string prop: string type: string defaultValue?: unknown } export interface LcWorkbenchOptions { silence?: boolean getDictTypes: () => Promise getApis: () => Promise getApi: (code: string) => Promise icons: { renderer: (props: { modelValue: string | null, onUpdateModelValue: (modelValue: string | null) => void }) => VNode } file: { removeFile: (fileId: string) => Promise getFileInfos: (fileIds: string[]) => Promise<{ id: string name: string size: number url: string type: string }[]> previewFileUrl: (fileId: string) => string downloadFileUrl: (fileId: string) => string uploadFile: (file: File, options?: { onProgress?: ((percent: number) => void) | undefined }) => Promise } materials: Record mapPropItems?: ( items: LcMaterialPropItem[], ops: { type: string, props: Record, engine: LowcodeEngineWorkbench }, ) => LcMaterialPropItem[] mapProItems?: ( items: LcMaterialPropItem[], ops: { type: string, props: Record, engine: LowcodeEngineWorkbench }, ) => LcMaterialPropItem[] templates?: Record[] }> stateDefinitions?: StateType[] methodDefinitions?: MethodType[] providers?: Record providerDocs?: ProviderDoc[] } type InsertParams = Extra & { index?: number slot?: string replace?: boolean } export declare class LowcodeEngineWorkbench< MaterialNameMap extends {} = Record, > extends LowcodeEngineCore { revocable: boolean redoable: boolean set schema(schema: Partial) get schema(): LcSchema materials: Record templates: Record readonly materialMap: Map Workbench: DefineComponent< { terminal: PropType<'WEB' | 'MOBILE'> }, {}, { onRefresh?: () => void onSubmit?: (schema: LcSchema) => void } > current: LcNode hovered?: LcNode constructor(_: LcWorkbenchOptions) addState( name: string, type: T, description: string, config: PartialKeys, ): Promise removeState(name: string): void addMethod( name: string, type: T, description: string, config: PartialKeys, ): Promise<() => void> removeMethod(name: string): void undo: (pointer?: number) => void redo: (pointer?: number) => void historyStack: ReturnType toJSON(): Required createNode( type: T, defaults?: Partial & { css: CSSProperties, css2: CSSProperties }>, reuse?: boolean, ): LcNode> insertNode( node: Node, parent?: ParentNode, ops?: number | InsertParams>, ): Node } export interface LcMaterial { name: string key: Name icon: Component component?: DefineComponent | (() => Promise) render?: >( props: Record, options: { slots: Slots }, engine: LowcodeEngineWorkbench, ) => VNodeChild onChildAdd?: ( child: LcNode, options: { node: LcNode, engine: LowcodeEngineWorkbench } & InsertParams, ) => LcNode | undefined | void wrap?: boolean | 'before' | 'after' form?: boolean inline?: boolean custom?: { size?: boolean text?: boolean box?: boolean border?: boolean background?: boolean boxShadow?: boolean position?: boolean } modelValue?: string events?: (string | [string, string | ((params: { props: Record }) => string)])[] props?: Record | (() => Record) css?: (cls: string) => CSSProperties css2?: (cls: string) => CSSProperties items: (node: LcNode) => LcMaterialPropItem[] __extra?: Extra } export interface LcComponent { key: string component?: Component | (() => Promise) render?: (props: Record, options: { slots: Slots }, engine: LowcodeEngineCore) => VNodeChild } export interface LcTemplate> { name: string key: string icon: Component generate(engine: LowcodeEngineWorkbench): Promise } interface _LcStateDefinition { label: string key: string color?: string install: >( name: string, config: Config, engine: LowcodeEngineWorkbench, ) => MaybePromise uninstall: >( name: string, config: Config, engine: LowcodeEngineWorkbench, ) => void apply: (name: string, config: Config, engine: LowcodeEngineCore) => MaybePromise getTip: ( name: string, config: Config, engine: LowcodeEngineCore, ) => MaybePromise getDefault: () => Partial config: (config: Config, engine: LowcodeEngineWorkbench) => VNodeChild } export type LcStateDefinition< Config extends StateDefinitions[keyof StateDefinitions], IsRenderer extends boolean = false, > = IsRenderer extends true ? Pick<_LcStateDefinition, 'key' | 'apply'> : _LcStateDefinition interface _LcMethodDefinition { label: string key: string color?: string install: >( name: string, config: Config, engine: LowcodeEngineWorkbench, ) => MaybePromise uninstall: >( name: string, config: Config, engine: LowcodeEngineWorkbench, ) => void apply: (name: string, config: Config, engine: LowcodeEngineCore) => MaybePromise getTip: (name: string, config: Config, engine: LowcodeEngineCore) => MaybePromise getDefault: () => Partial config: (config: Config, engine: LowcodeEngineWorkbench) => VNodeChild } export type LcMethodDefinition< Config extends MethodDefinitions[keyof MethodDefinitions], IsRenderer extends boolean = false, > = IsRenderer extends true ? Pick<_LcMethodDefinition, 'key' | 'apply'> : _LcMethodDefinition export interface EntityApi { ( this: void, method: HttpMethod, model: string, params?: Record, ): Promise<{ status: boolean code: number message: string data: R headers: Headers }> fetchOne = Record>( this: void, config: Required>, id: string, ): Promise deleteOne(this: void, config: Required>, id: string): Promise deleteBatch( this: void, config: Required>, ids: string[], ): Promise postOne( this: void, config: Required>, one: Record, ): Promise putOne( this: void, config: Required>, one: Record, ): Promise fetchList = Record>( this: void, config: Required>, params: Record, ): Promise fetchPage = Record>( this: void, config: Required>, params: { query: Record pagin: { currentPage: number, pageSize: number } sort: { name: string, order: 'asc' | 'desc' } }, ): Promise> } export declare function getFieldFormMap>(): Partial< Record< EntityFieldType, [ type: keyof MaterialNameMap | ((field: EntityField, custom: Record) => keyof MaterialNameMap), model: ( field: EntityField, custom: Record, ) => [ Record, Partial & { css: CSSProperties, css2: CSSProperties }>?, ], formItemModel: ( field: EntityField, ) => [ Record, Partial & { css: CSSProperties, css2: CSSProperties }>?, ], ] > > export declare function getFieldQueryFormMap>(): Partial< Record< EntityFieldType, [ keyof MaterialNameMap | ((field: EntityField, custom: Record) => keyof MaterialNameMap), ( field: EntityField, custom: Record, ) => [ Record, Partial & { css: CSSProperties, css2: CSSProperties }>?, ], string?, ] > >